TcpListen和TcpClient的例子
服务端: SERVER SEND RECEIVE
TcpListener tl = new TcpListener(IPAddress.Any, 9999);
Socket s = tl.AcceptSocket();
byte[] bt = new byte[1024];
int count = s.Receive(bt);
string msg = null;
msg = Encoding.Unicode.GetString(bt, 0, count).ToString();
s.Send(Encoding.Unicode.GetBytes(str));
tl.Stop();
客户端: CLIENT SEND RECEIVE
TcpClient client = new TcpClient();
client.Connect("192.168.0.52", 9999);
client.Client.Send(Encoding.Unicode.GetBytes("get_friend_list"));
byte[] word = new byte[1024];
int count = client.Client.Receive(word);
string msg = Encoding.Unicode.GetString(word, 0, count).ToString();
client.Close();