0
System.Net.Sockets.SocketException: '無効な引数が与えられた'System.Net.Sockets.SocketException: '無効な引数が与えられた'
_socket.Connect(Dns.GetHostAddresses("vcap.me"), 1832);
全コード:
namespace App.Root.Core.Network.Sockets
{
class SocketHandler
{
private readonly Socket _socket;
private readonly Timer _timer;
public SocketHandler()
{
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_timer = new Timer(OnTick, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
}
private void Connect()
{
if (IsConnected())
{
return;
}
_socket.Connect(Dns.GetHostAddresses("vcap.me"), 1832);
}
private bool IsConnected()
{
return !((_socket.Poll(1000, SelectMode.SelectRead) && (_socket.Available == 0)) || !_socket.Connected);
}
private void OnTick(object obj)
{
if (!IsConnected())
{
CoreUtilities.LogToConsole("Connecting to the server...");
Connect();
}
}
}
}
私が行うのは、SocketHandlerコンストラクタを初期化することだけです。