views:

187

answers:

1

I'm in the process of building a client/server based game for a project(feeling quite out my depth). I've been using TCPclient and a multi-threaded socket server. Everything is working fine at the moment but I have been using StreamReader and StreamWriter to communicate between both client and server.

I keep seeing examples like this for recieving data:

byte[] data = new byte[1024];
int recv = sock.ReceiveFrom(data, ref ep);
string stringData = Encoding.ASCII.GetString(data, 0, recv);

and this for sending:

byte[] data = Encoding.ASCII.GetBytes("This is a test message");
server.SendTo(data, iep);

I was wondering what are the benefits of using this over streamReader? Would using this also be buffering?

Thanks in advance.

+3  A: 

It's just a different style. ReceiveFrom and SendTo are more Unix-style, and using a StreamReader is more of a .NET style. StreamReader would be of more use to you, as you could then pass it to other methods that accept a TextReader.

John Saunders
Thank you for the replies. I am going to be sticking with streamReader but would like to know if it provides any buffering?
SlowForce
I don't know whether it adds any buffering. I doubt it. However, the underlying stream certainly has some buffering of the network traffic.
John Saunders