Now I send messages using:

void SendToSocket(SOCKET &soc,string &str) { send(soc, str.c_str(), str.size() + 1, 0);//WinSock2.h } 

But in this way only the lines are "forwarded". How to transfer an arbitrary array of data? Type int[] , but so that they are guaranteed to come in their own order and not separate some characters (char) from there by the automaton during transmission or reception. Now the text sends the application to c ++, and receives the ubuntu terminal via telnet. Is it enough just to send and receive an unsigned char array instead of string?

  • The socket does not send strings, the socket sends bytes. Pass the array address and length in bytes. What would be no loss, you need to transfer more and length. - nick_n_a
  • @nick_n_a char p[] = "Welcome!"; send(client, &p, sizeof(p), 0); char p[] = "Welcome!"; send(client, &p, sizeof(p), 0); gives an error that const char(*) is not a const char* (talking about p ). What am I doing wrong? - Vasily Pupkin
  • In your example, p is already a pointer, you need to pass it right away, not &p . - RiotBr3aker
  • (1) copy the array from a string literal to an array on the stack (2) pass the array address without a cast (3) use sizeof to determine the size of the array (4) do not check the result send @ RiotBr3aker No, in this example p not a pointer, it is an array . - VTT
  • @VTT how to check send result? There is no client application yet. - Vasily Pupkin

0