C# sockets server unable to receive data from same client connection more than once?

You must call Accept() only once per client, not every time you want to receive new data. Accept() basically waits for a client to connect to your server socket, s1 (and returns a new socket to send/receive data with this client), so here each time your Receive() function is called your socket waits for another client to connect, that's why it works only once.

You must call Accept() only once per client, not every time you want to receive new data. Accept() basically waits for a client to connect to your server socket, s1 (and returns a new socket to send/receive data with this client), so here each time your Receive() function is called your socket waits for another client to connect, that's why it works only once. Here is an example (the code comes from your previous question) : s1.

Bind(endP); s1. Listen(10); Socket s2 = s1.Accept(); // Waits for a client to connect and return a socket, s2, to communicate with him while (true) { Receive(s2); } ... Receive() function : public void Receive(Socket s) { try { byte bytes = new byte256; received = s. Receive(bytes); receivedText.

Text += System.Text.ASCIIEncoding.ASCII. GetString(bytes); } catch (SocketException e) { Console. WriteLine("{0} Error code: {1}.", e.

Message, e. ErrorCode); return; } }.

Thanks! I've set up my program so pressing the receive button calls Receive() on the second socket I get from Accept() but only Accept()s once. – Boumbles Feb 22 at 14:01 You're welcome.

Don't forget to accept my answer if I solved your problem (click on the check mark on the left) – LadaRaider Feb 22 at 14:14.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions