AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Module: Sockets_hz ( listenning + nonblocking ) ... working :) (https://forums.alliedmods.net/showthread.php?t=60026)

hackziner 08-25-2007 13:30

Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
3 Attachment(s)
It's a modification of the socket module.

I've added 3 functions.

PHP Code:

/* Opens a new listenning connection bind to hostname:port via protocol (either SOCKET_TCP or SOCKET_UDP),
 * returns a socket (positive) or negative or zero on error.
 * States of error:
 * 0 - no error
 * 1 - error while creating socket
 * 2 - couldn't resolve hostname
 * 3 - couldn't connect to given hostname:port 
*/

native socket_listen(const _hostname[], _port_protocol SOCKET_TCP, &_error); 

PHP Code:

/* Set a socket in unblocking mode */

native socket_unblock(_socket); 

PHP Code:

native socket_close(_socket);

/* Accept a connection on a listenning socket 
 * returns a socket (positive) or negative or zero on error. */

native socket_accept(_socket); 

With UDP you've just to create a listenning socket to get incoming messages and create a socket to reply.

With TCP you've to create a listenning socket and accept connections.

To avoid socket_accept block. Set the listenning socket to nonblocking mode with socket_unblock.


Todo:
add: incoming packet address in socket_accept
add: function to see the address when receive a package of a listenning socket.

toazron1 08-25-2007 13:46

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
Can you add an example of this in action?

hackziner 08-25-2007 14:50

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
...

Alka 08-25-2007 14:53

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
Nice work hackziner! :up:

@toazron1 - http://forums.alliedmods.net/showpos...1&postcount=16

toazron1 08-25-2007 15:07

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
Quote:

Originally Posted by Alka (Post 523194)
Nice work hackziner! :up:

@toazron1 - http://forums.alliedmods.net/showpos...1&postcount=16

Thanks

hackziner 08-25-2007 15:57

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
I'm very sorry but people keep asking thing like this ... and I'm keep replying I've no enough time ...

You should ask to ramono his code with the new socket_unblock function ...

Ramono 08-29-2007 10:04

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
I don't get it, so all u have to do is call
socket_unblock(_socket)
then
socket_accept(_socket)

and it doesnt block?

or..?

Anyway, can somone compile this for win32 please?

toazron1 08-29-2007 10:20

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
There is a win32 in the other thread, however, I'm not 100% positive that it is the newest version.

Ramono 08-29-2007 10:52

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
Quote:

Originally Posted by toazron1 (Post 524830)
There is a win32 in the other thread, however, I'm not 100% positive that it is the newest version.

It isnt.

Hawk552 08-29-2007 11:58

Re: Module: Sockets_hz ( listenning + nonblocking ) ... working :)
 
Quote:

Originally Posted by toazron1 (Post 524830)
There is a win32 in the other thread, however, I'm not 100% positive that it is the newest version.

Hey! You stole my old avatar!


All times are GMT -4. The time now is 04:13.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.