Raised This Month: $32 Target: $400
 8% 

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


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
hackziner
Senior Member
Join Date: Sep 2006
Location: France
Old 08-25-2007 , 13:30   Module: Sockets_hz ( listenning + nonblocking ) ... working :)
Reply With Quote #1

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.
Attached Files
File Type: inc sockets_hz.inc (2.2 KB, 1987 views)
File Type: zip sockets_hz.zip (56.7 KB, 2268 views)
File Type: so sockets_hz_amxx_i386.so (11.3 KB, 3524 views)
__________________

Last edited by hackziner; 03-09-2009 at 18:46.
hackziner is offline
Send a message via ICQ to hackziner Send a message via AIM to hackziner Send a message via MSN to hackziner Send a message via Yahoo to hackziner Send a message via Skype™ to hackziner
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:35.


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