This C# library contains a class for handling the TCP-connection. It provides methods for connecting to a TCP-server or creating your own. Also, send and receive methods are implemented.
Either copy the class directly to your code or use the .dll provided in Releases.
The .NET Framework Version of your project should be 4.7.2 or higher since this library was build for the .NET Standard 2.0.
Following methods can be called:
- bool TryConnect(string ipAdress, int port) - Returns true, if the client could connect to the server.
- bool TryListen(int port) - Returns true, if a client could successfully connect to the listener. (This method is blocking)
- bool TryListen(int port, out string RemoteEndpointAddress ) - Returns true, if a client could successfully connect to the listener (server). In addition, the string-argument
RemoteEndpointAddress
is passed by reference. (This method is blocking) - void Disconnect() - Stops reading data, closes the client/listener, clears the receive buffer and sets the
TcpConnected
-flag to false. - void Dispose() - Runs
Disconnect()
. - bool TrySend(string sendString) - Returns true, if the
sendString
could be successfully sent. - bool TryReadingData() - Returns true, if the "readingThread" could be successfully started.
- void StopReadingData() - Stops the "readingThread".
- string GetReceivedString() - Returns the received string or
null
, if no string was received yet.
Following properties can be read:
- TcpIsConnected - Is true, if a working TCP connection exists.
An example program can be found in my TCP_Server_Client_Tester-repository.
TcpConnection_Lib-versions | TCP_Server_Client_Tester-versions | |
---|---|---|
v1.0.0 | -> | v1.0.0 |
v2.0.0 | -> | v2.0.0 |
- Visual Studio 2019 - IDE used for programming
- .NET Standard - .NET Standard 2.0 used
Daniel Duller - dadul96
This project is licensed under the MIT License - see the LICENSE file for details