2004-09-10 03:12:38 +00:00
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* AMX Mod X Module
|
|
|
|
|
* Basic Socket Functions
|
|
|
|
|
*
|
|
|
|
|
* Codebase from Ivan, -g-s-ivan@web.de (AMX 0.9.3)
|
|
|
|
|
* Modification by Olaf Reusch, kenterfie@hlsw.de (AMXX 0.16, AMX 0.96)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#if defined _socket_included
|
|
|
|
|
#endinput
|
|
|
|
|
#endif
|
|
|
|
|
#define _socket_included
|
|
|
|
|
|
2006-05-10 10:42:49 +00:00
|
|
|
|
#if AMXX_VERSION_NUM >= 175
|
|
|
|
|
#pragma reqlib sockets
|
|
|
|
|
#if !defined AMXMODX_NOAUTOLOAD
|
|
|
|
|
#pragma loadlib sockets
|
|
|
|
|
#endif
|
|
|
|
|
#else
|
|
|
|
|
#pragma library socket
|
|
|
|
|
#endif
|
2005-07-15 19:05:31 +00:00
|
|
|
|
|
2004-09-10 03:12:38 +00:00
|
|
|
|
// Use SOCKET_TCP for TCP Socket connections
|
|
|
|
|
|
|
|
|
|
#define SOCKET_TCP 1
|
|
|
|
|
|
|
|
|
|
// Use SOCKET_UDP for UDP Socket connections
|
|
|
|
|
|
|
|
|
|
#define SOCKET_UDP 2
|
|
|
|
|
|
|
|
|
|
/* Opens a new connection 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
|
|
|
|
|
*/
|
|
|
|
|
|
2007-01-26 05:56:10 +00:00
|
|
|
|
native socket_open(const _hostname[], _port, _protocol = SOCKET_TCP, &_error);
|
2004-09-10 03:12:38 +00:00
|
|
|
|
|
|
|
|
|
/* Closes a Socket */
|
|
|
|
|
|
|
|
|
|
native socket_close(_socket);
|
|
|
|
|
|
|
|
|
|
/* Recieves Data to string with the given length */
|
|
|
|
|
|
|
|
|
|
native socket_recv(_socket, _data[], _length);
|
|
|
|
|
|
|
|
|
|
/* Sends data to the Socket */
|
|
|
|
|
|
2007-01-26 05:56:10 +00:00
|
|
|
|
native socket_send(_socket, const _data[], _length);
|
2004-09-10 03:12:38 +00:00
|
|
|
|
|
2005-12-05 01:49:16 +00:00
|
|
|
|
/* Same as socket_send but Data can contain null bytes */
|
|
|
|
|
|
2007-01-26 05:56:10 +00:00
|
|
|
|
native socket_send2(_socket, const _data[], _length);
|
2005-12-05 01:49:16 +00:00
|
|
|
|
|
2004-09-10 03:12:38 +00:00
|
|
|
|
/* This function will return true if the state (buffer content) have changed within the last recieve or
|
|
|
|
|
* the timeout, where timeout is a value in <EFBFBD>Seconds, (1 sec =1000000 <EFBFBD>sec).
|
|
|
|
|
* Use to check if new data is in your socket. */
|
|
|
|
|
|
|
|
|
|
native socket_change(_socket, _timeout=100000);
|