mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-23 12:39:35 +08:00
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
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;
|
|
|
|
namespace Milimoe.FunGame.Core.Service
|
|
{
|
|
internal class SocketManager
|
|
{
|
|
internal static Socket? Connect(string IP, int Port = 22222)
|
|
{
|
|
Socket? socket = null;
|
|
EndPoint ServerEndPoint;
|
|
try
|
|
{
|
|
socket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
|
ServerEndPoint = new IPEndPoint(IPAddress.Parse(IP), Port);
|
|
if (ServerEndPoint != null)
|
|
{
|
|
while (true)
|
|
{
|
|
if (!socket.Connected)
|
|
{
|
|
socket.Connect(ServerEndPoint);
|
|
if (socket.Connected)
|
|
{
|
|
return socket;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
socket?.Close();
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|