title: How to send something to the server?
body: <p>I was given this code and my task is to send something to the server using the console and read it in it.</p>
  <p>Maybe someone knows how to do it for me or maybe give me a hint where to start.</p>
  <p>Because we were given the source  code but how to work with it and what to do next, we were not told anything</p>
  <p>Maybe someone already has experience in this and can help</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;winsock2.h&gt;
  #include &lt;ws2tcpip.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;string.h&gt;
  #pragma comment (lib, &quot;Ws2_32.lib&quot;)
  
  int main() {
  
      WSADATA wsaData;
      int iResult;
  
      iResult = WSAStartup(MAKEWORD(2, 2), &amp;wsaData);
      if (iResult != 0) {
          printf(&quot;WSAStartup failed: %d\n&quot;, iResult);
          return 1;
      }
  
      struct addrinfo *result = NULL, *ptr = NULL;
      struct addrinfo hints;
  
      ZeroMemory(&amp;hints, sizeof(hints));
      hints.ai_family = AF_UNSPEC;
      hints.ai_socktype = SOCK_STREAM;
      hints.ai_protocol = IPPROTO_TCP;
  
      iResult = getaddrinfo(&quot;147.175.115.34&quot;, &quot;777&quot;, &amp;hints, &amp;result);
      if (iResult != 0) {
          printf(&quot;getaddrinfo failed: %d\n&quot;, iResult);
          WSACleanup();
          return 1;
      } else
          printf(&quot;getaddrinfo did not fail...\n&quot;);
  
  
      SOCKET ConnectSocket = INVALID_SOCKET;
  
      ptr = result;
  
      ConnectSocket = socket(ptr-&gt;ai_family, ptr-&gt;ai_socktype, ptr-&gt;ai_protocol);
  
      if (ConnectSocket == INVALID_SOCKET) {
          printf(&quot;Error at socket(): %d\n&quot;, WSAGetLastError());
          freeaddrinfo(result);
          WSACleanup();
          return 1;
      } else
          printf(&quot;Any error occured...\n&quot;);
  
  
      iResult = connect(ConnectSocket, ptr-&gt;ai_addr, (int) ptr-&gt;ai_addrlen);
  
      if (iResult == SOCKET_ERROR)
          printf(&quot;Not connected to server...\n&quot;);
      else
          printf(&quot;Connected to server!\n&quot;);
  
      if (iResult == SOCKET_ERROR) {
          closesocket(ConnectSocket);
          ConnectSocket = INVALID_SOCKET;
          WSACleanup();
          return 1;
      }
  
      Sleep(250);
  
      char sendbuf[4096];
  
      iResult = send(ConnectSocket, sendbuf, (int)strlen(sendbuf), 0);
      if (iResult == SOCKET_ERROR)
      {
          printf(&quot;send failed: %d\n&quot;, WSAGetLastError());
          closesocket(ConnectSocket);
          WSACleanup();
          return 1;
      }
  
      printf(&quot;Bytes Sent: %d\n&quot;, iResult);
  
  #define DEFAULT_BUFLEN 4096
  
      int recvbuflen = DEFAULT_BUFLEN;
      char recvbuf[DEFAULT_BUFLEN];
  
  
      iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
      if ( iResult &gt; 0 )
          printf(&quot;Bytes received: %d\n&quot;, iResult);
      else if ( iResult == 0 )
          printf(&quot;Connection closed\n&quot;);
      else
          printf(&quot;recv failed with error: %d\n&quot;, WSAGetLastError());
      closesocket(ConnectSocket);
      WSACleanup();
  }
  </code></pre>