📄 controlserver.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net ;
using System.Net .Sockets ;
using System.Threading ;
namespace mychatserver
{
public class controlserver
{
public TcpListener client;
public controlserver()
{
}
public OutDelegate havenewuser;
public void startserver()
{
IOxml xml1 = new IOxml();
IPAddress addr = IPAddress.Parse(xml1.GetIP());
int port = xml1.GetPort();
client = new TcpListener(addr,port);
client.Start();
while (true)
{
while (!client.Pending())
{
Thread.Sleep(1000);
}
ConnectionThread newconnection = new ConnectionThread();
newconnection.threadListener = this.client;
newconnection.newuserinfocoming += havenewuser;
Thread newthread = new Thread(new ThreadStart(newconnection.HandleConnection));
newthread.Start();
}
}
class ConnectionThread
{
public event OutDelegate newuserinfocoming;
public TcpListener threadListener;
private static int connections = 0;
public void HandleConnection()
{
try
{
int recv;
byte[] data = new byte[1024];
TcpClient client = threadListener.AcceptTcpClient();
connections++;
string str = client.Client.RemoteEndPoint.ToString() + "登陆........时间:" + System.DateTime.Now.ToString();
newuserinfocoming(str);
}
catch
{
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -