Fix bug: Encoding.UTF8 caused Unhandled exception
This commit is contained in:
parent
db13bfa39c
commit
e0866921c3
|
@ -11,7 +11,7 @@ namespace AsterNET.IO
|
||||||
private TcpClient tcpClient;
|
private TcpClient tcpClient;
|
||||||
private NetworkStream networkStream;
|
private NetworkStream networkStream;
|
||||||
private StreamReader reader;
|
private StreamReader reader;
|
||||||
private StreamWriter writer;
|
private BinaryWriter writer;
|
||||||
private Encoding encoding;
|
private Encoding encoding;
|
||||||
private bool initial;
|
private bool initial;
|
||||||
|
|
||||||
|
@ -29,8 +29,7 @@ namespace AsterNET.IO
|
||||||
this.tcpClient = new TcpClient(host, port);
|
this.tcpClient = new TcpClient(host, port);
|
||||||
this.networkStream = this.tcpClient.GetStream();
|
this.networkStream = this.tcpClient.GetStream();
|
||||||
this.reader = new StreamReader(this.networkStream, encoding);
|
this.reader = new StreamReader(this.networkStream, encoding);
|
||||||
this.writer = new StreamWriter(this.networkStream, encoding);
|
this.writer = new BinaryWriter(this.networkStream, encoding);
|
||||||
this.writer.AutoFlush = true;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -47,8 +46,7 @@ namespace AsterNET.IO
|
||||||
this.tcpClient = tcpClient;
|
this.tcpClient = tcpClient;
|
||||||
this.networkStream = this.tcpClient.GetStream();
|
this.networkStream = this.tcpClient.GetStream();
|
||||||
this.reader = new StreamReader(this.networkStream, encoding);
|
this.reader = new StreamReader(this.networkStream, encoding);
|
||||||
this.writer = new StreamWriter(this.networkStream, encoding);
|
this.writer = new BinaryWriter(this.networkStream, encoding);
|
||||||
this.writer.AutoFlush = true;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -156,7 +154,8 @@ namespace AsterNET.IO
|
||||||
/// <summary>connection has already been closed.</summary>
|
/// <summary>connection has already been closed.</summary>
|
||||||
public void Write(string s)
|
public void Write(string s)
|
||||||
{
|
{
|
||||||
writer.Write(s);
|
writer.Write(encoding.GetBytes(s));
|
||||||
|
writer.Flush();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue