Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A simple TCP server sample
- #include <a_samp>
- #include <socket>
- new Socket:g_Socket;
- public OnFilterScriptInit()
- {
- g_Socket = socket_create(TCP);
- if(is_socket_valid(g_Socket)) {
- socket_set_max_connections(g_Socket, 10);
- socket_listen(g_Socket, 1337);
- }
- return 1;
- }
- public OnFilterScriptExit()
- {
- if(is_socket_valid(g_Socket))
- socket_destroy(g_Socket);
- }
- public onSocketRemoteConnect(Socket:id, remote_client[], remote_clientid)
- {
- printf("Incoming connection from [%d:%s]", remote_clientid, remote_client); // [id:ip]
- new str[50] = "Welcome";
- socket_send(id, str, strlen(str));
- printf("Socket send");
- return 1;
- }
- public onSocketRemoteDisconnect(Socket:id, remote_clientid)
- {
- printf("Remote client [%d] has disconnected.", remote_clientid); // [id:ip]
- return 1;
- }
- public onSocketReceiveData(Socket:id, remote_clientid, data[], data_len)
- {
- printf("Remote client [%d] has sent: %s", remote_clientid, data); // id & data
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement