using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Text; using System.Net.Sockets; using System.Threading; using System.Net.NetworkInformation; using System.Text.RegularExpressions; using System.Net; namespace JXSoft { public class TCPServerModel:DataEventModel { public override void setLinkState(int linkState) { } public override int getLinkState() { return 0; } protected override void OnInit() { } } public class TCPServerUtility { public Socket tcpServer; /// /// 开启服务 /// /// 端口号 /// 最大连接数 public void startServer(int port,int maxLink) { try { //点击开始监听时 在服务端创建一个负责监听IP和端口号的Socket tcpServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ip = IPAddress.Parse("127.0.0.1"); //创建对象端口 IPEndPoint point = new IPEndPoint(ip, port); tcpServer.Bind(point);//绑定端口号 Debug.Log("监听成功!"); tcpServer.Listen(maxLink);//设置监听,最大同时连接10台 } catch { } } } }