Home > Software engineering >  The problem of win32 TCP communications straight to send and receive data
The problem of win32 TCP communications straight to send and receive data

Time:09-22

Encapsulates a mysocket class myself, using win32 API for socket, inside is TCP communications, the role of this class is as a client, even to the specified server, and then interact with the server data, according to the TCP client communication steps, it should have been send a lot of time after the call recv at a time, I think it is very trouble, just do it himself a thread, thread in an infinite loop, has been receiving data, the problem is that my next time send need to receive the last response data, and then according to the analytic results to determine what to send message, I tried in receiving the child thread with postThreadMessage to implement, but this time the main thread will be stuck here in getmessage, excuse me have a better way to solve this problem

CodePudding user response:


What this is involved in design patterns, I'm with the method of interface callback, the callback function onRecv, or provide a GetMessage traversal method receives the packet

CodePudding user response:

reference 1st floor smwhotjay response:

What this is involved in design patterns, I'm with the method of interface callback, the callback function onRecv, GetMessage traversal or provide a method to receive packets


reference 1st floor smwhotjay response:

What this is involved in design patterns, I'm with the method of interface callback, the callback function onRecv, GetMessage traversal or provide a method to receive packets


Big brother, can you point in detail, this aspect I don't know ah, thank you

CodePudding user response:

If not the UI thread, you should use the Event or Mutex synchronization semaphore
If the UI thread is using the PeekMessage

CodePudding user response:

reference zgl7903 reply: 3/f
if it is not the UI thread, you should use the Event or Mutex synchronization semaphore
If the UI thread is using the PeekMessage

This is not to the UI design, is I want to do a special class for the socket communication, this is in a class,

CodePudding user response:

Don't know how many predecessors in the TCP Socket
Send (many) send (less) send (wealth)
Has been so much illness recv (), recv (wealth)
Inside the trap!
http://bbs.csdn.net/topics/380167545

CodePudding user response:

You don't have to use postThreadMessage, also you can use a global buffer, two threads used together, then add synchronization

CodePudding user response:

WSAAsyncSelect used to send and receive message mechanism

CodePudding user response:

Actually completely don't need so complicated, using circular linked list, in rev strcut xx {int sign; Char * data; } to save the received data, and finish each receive a package, sign 1 said that has data chain table,,

Then, send the circulation judge whether there is a sign of 1, copy the data to the buffer, sign set 0.

In fact as long as it's not involve the p2p client, for hardware resources, no pressure.

CodePudding user response:

Of course it's better if have synchronous list.

CodePudding user response:

The questions you ask two, not too thin:
1) about the Socket communication, if it is a Windows environment, overlapping IO may have a look, there are many examples, based on the event notification model, can solve your "when to go to receive" problem,
2) about the thread synchronization, generally suggest using lock synchronization queue + event notification, in the form of production, consumption patterns, not too big to use postThreadMessage system such as the API to intervene,

CodePudding user response:

Receive a thread with WSAWaitForMultipleEvents model, processing, finished receiving process select the send content, the process is clear; Under the complex IOCP to understand
  • Related