日期:2014-05-18 浏览次数:21028 次
//Client 端
private void sendMsg()
{
try
{
tClient = new TcpClient(new IPEndPoint(IPAddress.Parse("10.111.3.35"), 8001));//指定端口
tClient.Connect("10.111.3.35", 8080);
ns = tClient.GetStream();
private void receiveMsg()
{
try
{
msgListener = new TcpListener(8001);//侦听同一个端口
msgListener.Start();
byte[] data = new byte[256];
int size = ns.Read(data,0,256);
string content = Encoding.Unicode.GetString(data, 0, size);
EndPoint EP = socketConn.RemoteEndPoint;
IPEndPoint iep = (IPEndPoint)EP;
if (content.Equals("exit"))
return false;
if (content.Equals("log"))
{
Client.addClient(iep);//服务器记录用户ip和端口,以便发起tcp会话使用
}