tobeyu
January 14th, 2003, 10:45 AM
what is the difference with these?? I know byte is an integral data type where Byte is a structure but when they both declare an unsigned 8-bit integer, what is the difference and why would you use one vs the other?
My problem is, I am playing around with a socket application and looking at the TcpClient example in MSDN, it declares a Byte[] to hold the data to send and a byte[] to hold the data to receive. This is confusing the heck out of me and I can't figure out why the difference.
From MSDN:
TcpClient tcpClient = new TcpClient();
// Uses the GetStream public method to return the NetworkStream.
try{
NetworkStream networkStream = tcpClient.GetStream();
if(networkStream.CanWrite){
Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there?");
networkStream.Write(sendBytes, 0, sendBytes.Length);
}
else{
Console.WriteLine("You cannot write data to this stream.");
tcpClient.Close();
return;
}
if(networkStream.CanRead){
// Reads NetworkStream into a byte buffer.
byte[] bytes = new byte[tcpClient.ReceiveBufferSize];
// Read can return anything from 0 to numBytesToRead.
// This method blocks until at least one byte is read.
networkStream.Read(bytes, 0, (int) tcpClient.ReceiveBufferSize);
// Returns the data received from the host to the console.
string returndata = Encoding.ASCII.GetString(bytes);
Console.WriteLine("This is what the host returned to you: " + returndata);
}
else{
Console.WriteLine("You cannot read data from this stream.");
tcpClient.Close();
return;
}
}
catch (Exception e ) {
Console.WriteLine(e.ToString());
}
Thanks in advance,
Tobey
My problem is, I am playing around with a socket application and looking at the TcpClient example in MSDN, it declares a Byte[] to hold the data to send and a byte[] to hold the data to receive. This is confusing the heck out of me and I can't figure out why the difference.
From MSDN:
TcpClient tcpClient = new TcpClient();
// Uses the GetStream public method to return the NetworkStream.
try{
NetworkStream networkStream = tcpClient.GetStream();
if(networkStream.CanWrite){
Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there?");
networkStream.Write(sendBytes, 0, sendBytes.Length);
}
else{
Console.WriteLine("You cannot write data to this stream.");
tcpClient.Close();
return;
}
if(networkStream.CanRead){
// Reads NetworkStream into a byte buffer.
byte[] bytes = new byte[tcpClient.ReceiveBufferSize];
// Read can return anything from 0 to numBytesToRead.
// This method blocks until at least one byte is read.
networkStream.Read(bytes, 0, (int) tcpClient.ReceiveBufferSize);
// Returns the data received from the host to the console.
string returndata = Encoding.ASCII.GetString(bytes);
Console.WriteLine("This is what the host returned to you: " + returndata);
}
else{
Console.WriteLine("You cannot read data from this stream.");
tcpClient.Close();
return;
}
}
catch (Exception e ) {
Console.WriteLine(e.ToString());
}
Thanks in advance,
Tobey