Home > Net >  Winform PC SOCKET, please god
Winform PC SOCKET, please god

Time:12-14

I have a PC, collecting data, one side is forwarding data, some strange problems, a great god, please help to reassure,
1. My program to create two socket listening port, the received data is sent to the corresponding page displays, everything is normal also very smooth, page display is almost a second when a record, I have a button to stop receiving, specific operation that the original data through an authorized to send to the page shows that when some stops, tied to entrust solution, the page will not receive data show that after a while I rebound, I found, according to the data will be super fast don't know what is this principle?
2. I later added a demand, that is, the port received data to be sent to another machine, I create two SOCKET client, when receiving port receives data, SOCKET is invoked by the client with the Send to Send, before and others is also a good alignment, alignment again after a while, we found that data is sent not to go out, use caught tools to see, as if not to, but I have a return value back, debugging shows that the Send method SocketFlag was added later in the Send method. None, just sent, then the alignment, seems to my program will be a problem, the third time alignment, don't know what each other is the change, I just start, after Send my application for a while the receiver data is not come, feeling is blocked, I stop after the Send, for a moment the received data is coming, don't know what it is, can analyze?
3. After I change the send method to sendAsync, as if the received data can be normal, but it didn't take long for my program will quote MEMEYOUTEXCEPTION, does this every time calling sendAsync, will open a thread lead to? Later, I try again, use the queue receiving data, using Send (byte, SocketFlag. None) and then open a thread in the main page to perform and if the queue number more than N, so will I fetch the data from the queue, but do not call the Send (byte, SocketFlag. None), I allow myself to discard some of the data, things seem to be all right now, the whole process is a little meng force!

CodePudding user response:

https://blog.51cto.com/walkerqt/1947585

About forwarding, we don't have to write code directly forwarding, because in fact, I really don't want to discuss your above.

Because now already changing environment, the above discussion that can be stopped, if we say that we only need to encapsulate a SocketTransport
https://github.com/rsocket/rsocket-net/blob/master/RSocket.Core/Transports/SocketTransport.cs

Then hang two Tranfer IDuplexPipe interface between each other it is good to answer it

CodePudding user response:

A synchronized block is generally used to write a practice temporary, try to use asynchronous multi-threaded approach to send and receive,

CodePudding user response:

A synchronized block, you like
 var len=XXXX. The Receive (buffer); 
such statements tend to clog your main thread, your application logic "short circuit", oneself didn't force yourself,

CodePudding user response:

The
reference 3 floor interacting in a professional developer response:
synchronous blocking, your similar
 var len=XXXX. The Receive (buffer); 
such statements tend to clog your main thread, your application logic "short circuit", make themselves meng,

The receive I am a new thread does not block the main thread
  •  Tags:  
  • C#
  • Related