Ash SR

Ash SR

  • NA
  • 1
  • 1.2k

Getting junk values while converting network stream to strin

Apr 8 2014 2:37 AM
I have tried to read a text file through command prompt. Using the following steps 1. Enabled telnet server in the server pc and client in my pc. 2. change telnet port in server pc to 24 3. Using telnet command connect to server pc. 4. from telnet window> using type display the content of the text file in command prompt.
Now I want to do the same from my c# code. I have written the following code:

TcpClient tcpclient = new TcpClient();
tcpclient.Connect(<ip address>, <port>);
NetworkStream ns = tcpclient.GetStream();
StreamReader streamReader = new StreamReader(ns);
byte[] msg = Encoding.ASCII.GetBytes("type <file location>");
string returnd = Encoding.ASCII.GetString(msg);
ns.Write(msg, 0, msg.Length);
StreamWriter streamWriter = new St byte[] bytes = new byte[tcpclient.ReceiveBufferSize];
int bytesread = tcpclient.ReceiveBufferSize;
ns.Read(bytes, 0, bytesread);
reamWriter(ns);
string returndata = Encoding.ASCII.GetString(bytes);

but my code is always giving some junk output like " ÿý%ÿûÿûÿý'ÿýÿý"