31
px-tcp1/ProtosXExercise/TcpClient.cs
Normal file
31
px-tcp1/ProtosXExercise/TcpClient.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user