您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
43 行
1.0 KiB
43 行
1.0 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using UnityEngine;
|
|
using Unity.Collections;
|
|
|
|
public class TCPServer : TCPConnection
|
|
{
|
|
TcpListener m_TcpListener;
|
|
|
|
protected override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
|
|
m_TcpListener = new TcpListener(IPAddress.Any, port);
|
|
m_TcpListener.Start();
|
|
Logger.Log($"Listening for connection on port {port}...");
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
if (m_TcpClient == null && m_TcpListener.Pending())
|
|
{
|
|
Logger.Log("Connection pending...");
|
|
m_TcpClient = m_TcpListener.AcceptTcpClient();
|
|
Logger.Log($"Connection established. {((IPEndPoint)m_TcpClient.Client.RemoteEndPoint).Address}");
|
|
}
|
|
|
|
base.Update();
|
|
}
|
|
|
|
protected override void OnDisable()
|
|
{
|
|
base.OnDisable();
|
|
|
|
m_TcpListener.Stop();
|
|
m_TcpListener = null;
|
|
}
|
|
}
|