32 lines
675 B
C#
32 lines
675 B
C#
using System;
|
|
using System.Net.Sockets;
|
|
using static System.Console;
|
|
|
|
namespace ProtosXdigitalDemo
|
|
{
|
|
internal class TcpClientConnector
|
|
{
|
|
private readonly string _ip;
|
|
private readonly int _port;
|
|
|
|
public TcpClientConnector(string ip, int port)
|
|
{
|
|
_ip = ip;
|
|
_port = port;
|
|
}
|
|
|
|
public TcpClient Connect()
|
|
{
|
|
try
|
|
{
|
|
return new TcpClient(_ip, _port);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
WriteLine($"[Error] Unable to connect to {_ip}:{_port} → {ex.Message}");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|