- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsHi I working on a server, I want to be able to recieve (read) a request, then send back. Then read, then send back, etc. without closing the socket.
Can someone give me an idea of how it is done?
right now I have
while(running)
{
client = server.AcceptTcpClient();
byte[] buffer;
string request = "";
stream = client.GetStream();
while (client.Connected)
{
request = "";
int read = 0;
while (stream.DataAvailable)
{
Console.WriteLine("reading
buffer = new byte[1024];
read += stream.Read(buffer, 0, buffer.Length - 1);
request += System.Text.ASCIIEncoding.
}
//now I take request, process it and send it back using stream.Write
// If I do not do client.close and then client = server.AcceptTcpClient again then I cannot read again. Can someone explain this to me, and how it is done, to keep the socket open all the time and just recieve and send back and forth?
}
}
thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: drichardsPosted on 2007-09-11 at 18:23:24ID: 19873285
It sounds like it is the client on the other end that is always creating a new connection. You should not drop the connection until you call Close, which means that if you need to do AcceptTcpClient again it is because the other end is not transmitting over the same TCP connection.
download.h tml) or a similar tool to monitor your network connection.
Try watching the network and see if the connection is closed by the remote end. You can use Wireshark (http://www.wireshark.org/