using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Milimoe.FunGame.Core.Interface.Base;
using System.Collections;
using System.Net.Sockets;
using System.Net;
using System.Text.Json;
using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Core.Service
{
internal class SocketManager
{
///
/// 客户端专用Socket
///
internal static Socket? Socket { get; private set; } = null;
///
/// 服务器端专用Socket
///
internal static Socket? ServerSocket { get; private set; } = null;
///
/// 创建服务器监听Socket
///
/// 监听端口号
/// 最大连接数量
/// 服务器端专用Socket
internal static Socket? StartListening(int Port = 22222, int MaxConnection = 0)
{
if (MaxConnection <= 0) MaxConnection = SocketSet.MaxConnection_General;
try
{
ServerSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ServerEndPoint = new(IPAddress.Any, Port);
ServerSocket.Bind(ServerEndPoint);
ServerSocket.Listen(MaxConnection);
return ServerSocket;
}
catch
{
ServerSocket?.Close();
}
return null;
}
///
/// 创建一个监听到客户端Socket
///
/// 客户端IP地址[0]和客户端Socket[1]
internal static object[] Accept()
{
if (ServerSocket is null) return Array.Empty