Advertisement
obernardovieira

Server Socket

Feb 26th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.83 KB | None | 0 0
  1. #include <a_samp>
  2. #include <socket>
  3.  
  4. new Socket:serversocket;
  5.  
  6. main() {
  7.     print("\n----------------------------------");
  8.     print(" Socket Server");
  9.     print("----------------------------------\n");
  10. }
  11. public OnGameModeInit() {
  12.     serversocket=socket_create(TCP);//cria um socket
  13.     socket_listen(serversocket,54678);//adiciona uma porta
  14.     socket_bind(serversocket,"127.0.0.1");//dá um nome ao socket
  15.     socket_set_max_connections(serversocket,10);//limita as conexoes instantaneas
  16.     return 1;
  17. }
  18. public onSocketReceiveData(Socket:id, remote_clientid, data[], data_len) {//quando receber data do client
  19.     printf("socketid %d | remote_clientid %d | mensagem %s | total carateres %d",_:id,remote_clientid,data,data_len);
  20.     socket_sendto_remote_client(id, remote_clientid, "Bem vindo ao socket server!");//envia data para o cliente
  21.     return 1;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement