Hi !!! I have one problem! I use StreamWriter to send (object) stream to server (not string). But how to read this object with StreamReader ???
The server who send stream (object):
private void SomeMethod(SqlDataReader reader)
{
string column = "ColumnName";
object stream = ReadFromDB(reader, column);
SendStream(stream);
}
public object ReadFromDB(SqlDataReader reader, string column)
{
List<string> dataFromColumn = new List<string>();
while (reader.Read())
{
dataFromColumn.Add((string)reader[column]);
}
object listWithData = dataFromColumn;
return listWithData;
}
public void SendStream(object stream)
{
TcpClient tcpConnection = new TcpClient();
tcpConnection.Connect(addressPort);
NetworkStream netStream = tcpConnection.GetStream();
using (StreamWriter strmWriter = new StreamWriter(netStream))
{
//netStream.WriteTimeout = 1000;
strmWriter.Write(stream);
strmWriter.Flush();
}
}
The client who need to read stream (object):
class StreamManager
{
public StreamManager(TcpClient tcpConnection)
{
this.netStream = tcpConnection.GetStream();
}
public List<string> ReciveResultFromDB()
{
char[] buffer = new char[4096];
List<string> getResultFromDB = new List<string>();
StreamReader strmReader = new StreamReader(netStream);
strmReader.Read(buffer, 0, buffer.Length);
// ??????????????????????
// ??????????????????????
return getResultFromDB;
}
private NetworkStream netStream;
}
Sorry for my bad English !!!