c# - Send or receive file or data over sockets simultanously -


My server sends ping every 10 seconds and disconnects the client if it expires in 20 seconds without the answer

If I really want to send a bigger file to the customer from the client or vice versa, sending () or received () ways can be blocked for a long time, that the customer will end immediately after sending it is.

Also when the sending method is running, then I can not use other threads to send other data to the same socket / or I am sending the stream and the file which I am sending (or I corrupt the file) Can I Corrupt

Should I just connect the client to another socket and connect it on a separate port on my server for long time to send / receive?

Edit: For example, the server sends a message

  Public Zero SendTo (System.Net.EndPoint toclient, byte [] data) {foreach (clientlist Customer Client) {if (client.s.RemoteEndPoint == toclient) {Lock (client.sendlock) {int size = data.Length; Byte [] shaped by bit = new byte [4]; Sizebytes = bit sign. Getbytes (size); Client.s.Send (sizebytes); Client.s.Send (data); In these situations you should actually have a dedicated ping port and one for a data transfer.  

Of course, you need to maintain two open connections per customer, but as far as I can see , The age of a connection is low, while the other (for ping) remains until the customer wants (or can) be connected to connect.

Regarding your code, if you are not for anything else, then it can be slightly shaky for clarity:

  var client = clients.FirstOrDefault (c = & gt; ; CsRemoteEndPoint == toclient); If (customer! = Null) {lock (client.sendlock) {int size = data.Length; Byte [] shaped by bit = new byte [4]; Sizebytes = bit sign. Getbytes (size); Client.s.Send (sizebytes); Client.s.Send (data); }}  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -