Socket

TCP and UDP sockets

void socket_init() Initialize the socket API. Must be called at least once per process before using any socket or host function. 'socket socket_new(udp : bool) Create a new socket, TCP or UDP void socket_close('socket) Close a socket. Any subsequent operation on this socket will fail void socket_send_char('socket, int) Send a character over a connected socket. Must be in the range 0..255 int socket_send('socket, buf : string, pos : int, len : int) Send up to len bytes from buf starting at pos over a connected socket. Return the number of bytes sent. int socket_recv('socket, buf : string, pos : int, len : int) Read up to len bytes from buf starting at pos from a connected socket. Return the number of bytes readed. int socket_recv_char('socket) Read a single char from a connected socket. void socket_write('socket, string) Send the whole content of a string over a connected socket. string socket_read('socket) Read the whole content of a the data available from a socket until the connection close. If the socket hasn't been close by the other side, the function might block. 'int32 host_resolve(string) Resolve the given host string into an IP address. string host_to_string('int32) Return a string representation of the IP address. string host_reverse('int32) Reverse the DNS of the given IP address. string host_local() Return the local host name. void socket_connect('socket, host : 'int32, port : int) Connect the socket the given host and port void socket_listen('socket, int) Listen for a number of connections 'socket array array socket_select(read : 'socket array, write : 'socket array, others : 'socket array, timeout : number?) Perform the select operation. Timeout is in seconds or null if infinite void socket_bind('socket, host : 'int32, port : int) Bind the socket for server usage on the given host and port 'socket socket_accept('socket) Accept an incoming connection request #address socket_peer('socket) Return the socket connected peer address composed of an (host,port) array #address socket_host('socket) Return the socket local address composed of an (host,port) array void socket_set_timeout('socket, timout : number?) Set the socket send and recv timeout in seconds to the given value (or null for blocking) void socket_shutdown('socket, read : bool, write : bool) Prevent the socket from further reading or writing or both. void socket_set_blocking('socket, bool) Turn on/off the socket blocking mode. 'poll socket_poll_alloc(int) Allocate memory to perform polling on a given number of sockets 'socket array socket_poll('socket array, 'pool, timeout : float) Perform a polling for data available over a given set of sockets. This is similar to socket_select except that socket_select is limited to a given number of simultaneous sockets to check.

© Haxe Foundation | Contribute to this page