All,
Is this adeqaute to close all resources associated with clientSocket?
public void readAll(String[] s)
{
using (TcpClient clientSocket = new TcpClient(host, port))
{
NetworkStream clientStream = clientSocket.GetStream();
StreamWriter toOmega = new StreamWriter(clientStream);
StreamReader fromOmega = new StreamReader(clientStream);
toOmega.Write(readTemp);
toOmega.Flush(); //Command is not sent until buffer is flushed
s[0] = fromOmega.ReadLine();
toOmega.Write(readHum);
toOmega.Flush();
s[1] = fromOmega.ReadLine();
}
}
Or should I do this (seems overkill):
public void readAll(String[] s)
{
using (TcpClient clientSocket = new TcpClient(host, port))
using (NetworkStream clientStream = clientSocket.GetStream())
using (StreamWriter toOmega = new StreamWriter(clientStream))
using (StreamReader fromOmega = new StreamReader(clientStream))
{
toOmega.Write(readTemp);
toOmega.Flush(); //Command is not sent until buffer is flushed
s[0] = fromOmega.ReadLine();
toOmega.Write(readHum);
toOmega.Flush();
s[1] = fromOmega.ReadLine();
}
}
Thanks,
-Bill