Home > Software engineering >  Questions about the socket communication GET/HTTP/1.1
Questions about the socket communication GET/HTTP/1.1

Time:10-02

In writing the socket multithreaded communication, receiving and sending messages sometimes can appear a puzzling the IP address of the connected, received information is GET/HTTP/1.1, and then lead to connect all broken, could you tell me what this mean,

CodePudding user response:

There are online crawler swept in a WEB page,
As for why lead to connect all disconnected, the problem was on your code,

CodePudding user response:

reference 1st floor CharlesSimonyi response:
there are online reptiles in the WEB page,
As for why lead to connect all disconnected, the problem was on your code,

Oh, oh, in this way,
Thank you, that I change the code,

CodePudding user response:

 UINT server_thd (LPVOID p) 
{
WSADATA WSADATA;
WORD wVersion;
WVersion=MAKEWORD (2, 2);
WSAStartup (wVersion, & amp; WsaData);

SOCKADDR_IN local_addr;
SOCKADDR_IN client_addr;
Int iaddrSize=sizeof (SOCKADDR_IN);
=(CSocketDemoDlg *) AfxGetApp CSocketDemoDlg * DLG () - & gt; GetMainWnd ();
Local_addr. Sin_family=AF_INET;
Local_addr. Sin_port=htons (5150);
Local_addr. Sin_addr. S_addr=htonl (INADDR_ANY);

Listen_sock=socket (AF_INET SOCK_STREAM, IPPROTO_TCP);

Bind (listen_sock, (struct sockaddr *) & amp; Local_addr, sizeof (SOCKADDR_IN));

Listen (listen_sock, 50);
While (1)
{
The sock=accept (listen_sock, (struct sockaddr *) & amp; Client_addr, & amp; IaddrSize);
Cstrings port;
Port. The Format (" % d ", int (ntohs (client_addr. Sin_port)));
DLG - & gt; The update (" connected from: "+ cstrings (inet_ntoa (client_addr. Sin_addr)) +" port: "+ port);

CreateThread (NULL, 0, Thread_1, (LPVOID) the sock, 0, NULL);//the new SOCKET to thread

}

return 0;
}

Could you help me have a look at this code has any problem, open program run this thread to listen, listen to create a new thread after the communication,

CodePudding user response:

Initiative is disconnect your program calls the shutdown/closesocket to disconnect?
  • Related