金铉Unity插件库 Unity版本2018.4.32f 目前包含本地化存储功能(根据类名存储读写),TCP客户端监听类型功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5 KiB

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;
/// <summary>
/// 开启服务
/// </summary>
/// <param name="port">端口号</param>
/// <param name="maxLink">最大连接数</param>
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 { }
}
}
}