日期:2014-05-16 浏览次数:20815 次
//这段代码是在一个异步方法中 其中m_tcpListener是一个TCPListener的实例
while (true)
{
TcpClient m_tcp = await m_tcpListener.AcceptTcpClientAsync();
NetworkStream ns = m_tcp.GetStream();
string Nowdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
string s = "消息过去了啊!!!!!!" + Nowdate;
Byte[] sbyt = Encoding.UTF8.GetBytes(s);
uint len = (uint)sbyt.Length;
ns.Write(BitConverter.GetBytes(len), 0, sizeof(uint));
ns.Write(sbyt, 0, sbyt.Length);
ns.Close();
try
{
m_tcp.Close();
this._textBox.Text = "Cut Successd";
}
catch (Exception)
{
}
}
//_SR是一个streamsocket 实例
HostName hServer = new HostName