simplsockets icon indicating copy to clipboard operation
simplsockets copied to clipboard

It could be a good library but... How to use it?

Open radiolondra opened this issue 4 years ago • 0 comments

No documentation. No samples. Nothing? For example: a sample of the function expected by the constructor will be appreciated. Whatever I did up now doesn't work. Thank you.

/// <summary>
/// The constructor.
/// </summary>
/// <param name="socketFunc">The function that creates a new socket. Use this to specify your socket constructor and initialize settings.</param>
/// <param name="messageBufferSize">The message buffer size to use for send/receive.</param>
/// <param name="communicationTimeout">The communication timeout, in milliseconds.</param>
/// <param name="maxMessageSize">The maximum message size.</param>
/// <param name="useNagleAlgorithm">Whether or not to use the Nagle algorithm.</param>
public SimplSocketClient(Func<Socket> socketFunc, int messageBufferSize = 65536, int communicationTimeout = 10000, int maxMessageSize = 10 * 1024 * 1024, bool useNagleAlgorithm = false)

Test code

....
var clientSocket = new SimplSocketClient(SocketFunction);
if (clientSocket.Connect(hostEndPoint))
{
    this.Invoke(new MethodInvoker(delegate ()
    {
        tbResult.AppendText(String.Format("Connected {0}{1}",
                   hostEndPoint.Address.ToString(), Environment.NewLine));
    }));
....
// I'm able to connect ONLY. Everything else (like SendReceive calls) throw exceptions
}

private Socket SocketFunction()
{
    Socket clientSocket;
    

    // Get host related information.
    IPHostEntry host = Dns.GetHostEntry(hostName);

    // Addres of the host.
    IPAddress[] addressList = host.AddressList;

    // Instantiates the endpoint and socket.
    hostEndPoint = new IPEndPoint(addressList[addressList.Length - 1], port);
    clientSocket = new Socket(hostEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

    return clientSocket;

}

radiolondra avatar May 20 '21 08:05 radiolondra