Skip to content

Commit

Permalink
Merge pull request #2837 from CosmosOS/feature/plugNet3
Browse files Browse the repository at this point in the history
✨ Add TCPClient.TCPClient(string hostname, int port) !
  • Loading branch information
valentinbreiz authored Dec 6, 2023
2 parents 197e3e0 + 969da87 commit b66602e
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions source/Cosmos.System2_Plugs/System/Net/Sockets/TcpClientImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public static void Ctor(TcpClient aThis)
{
}

public static void Ctor(TcpClient aThis, string hostname, int port)
{
Connect(aThis, hostname, port);
}

public static void Ctor(TcpClient aThis, Socket acceptedSocket)
{
_clientSocket = acceptedSocket;
Expand All @@ -39,30 +44,26 @@ public static int get_ReceiveBufferSize(TcpClient aThis)
return Cosmos.System.Network.IPv4.TCP.Tcp.TcpWindowSize;
}

public static void Connect(TcpClient aThis, string hostname, int port, [FieldAccess(Name = "System.Boolean System.Net.Sockets.TcpClient._active")] ref bool _active)
public static void Connect(TcpClient aThis, string hostname, int port)
{
var address = IPAddress.Parse(hostname);
var endpoint = new IPEndPoint(address, port);
IPAddress address = IPAddress.Parse(hostname);
IPEndPoint endpoint = new(address, port);

_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_clientSocket.Bind(endpoint);
_clientSocket.Connect(address, port);
_active = true;
Connect(aThis, endpoint);
}

public static void Connect(TcpClient aThis, IPAddress address, int port, [FieldAccess(Name = "System.Boolean System.Net.Sockets.TcpClient._active")] ref bool _active)
public static void Connect(TcpClient aThis, IPAddress address, int port)
{
var endpoint = new IPEndPoint(address, port);
IPEndPoint endpoint = new(address, port);

_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_clientSocket.Bind(endpoint);
_clientSocket.Connect(address, port);
_active = true;
Connect(aThis, endpoint);
}

public static void Connect(TcpClient aThis, IPEndPoint remoteEP, [FieldAccess(Name = "System.Boolean System.Net.Sockets.TcpClient._active")] ref bool _active)
private static void Connect(TcpClient aThis, IPEndPoint endpoint)
{
throw new NotImplementedException();
_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_clientSocket.Bind(endpoint);
_clientSocket.Connect(endpoint.Address, endpoint.Port);
}

public static void Connect(TcpClient aThis, IPAddress[] ipAddresses, int port)
Expand Down

0 comments on commit b66602e

Please sign in to comment.