Advertisement
Guest User

ddd

a guest
Feb 19th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. // A simple TCP server sample
  2.  
  3. #include <a_samp>
  4. #include <socket>
  5.  
  6. new Socket:g_Socket;
  7.  
  8. public OnFilterScriptInit()
  9. {
  10. g_Socket = socket_create(TCP);
  11.  
  12. if(is_socket_valid(g_Socket)) {
  13. socket_set_max_connections(g_Socket, 10);
  14. socket_listen(g_Socket, 1337);
  15. }
  16.  
  17.  
  18. return 1;
  19. }
  20.  
  21. public OnFilterScriptExit()
  22. {
  23. if(is_socket_valid(g_Socket))
  24. socket_destroy(g_Socket);
  25. }
  26.  
  27. public onSocketRemoteConnect(Socket:id, remote_client[], remote_clientid)
  28. {
  29. printf("Incoming connection from [%d:%s]", remote_clientid, remote_client); // [id:ip]
  30. new str[50] = "Welcome";
  31. socket_send(id, str, strlen(str));
  32. printf("Socket send");
  33. return 1;
  34. }
  35.  
  36. public onSocketRemoteDisconnect(Socket:id, remote_clientid)
  37. {
  38. printf("Remote client [%d] has disconnected.", remote_clientid); // [id:ip]
  39. return 1;
  40. }
  41.  
  42. public onSocketReceiveData(Socket:id, remote_clientid, data[], data_len)
  43. {
  44. printf("Remote client [%d] has sent: %s", remote_clientid, data); // id & data
  45. return 1;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement