Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
radiolondra opened this issue May 20, 2021 · 0 comments
Open

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

radiolondra opened this issue May 20, 2021 · 0 comments

Comments

@radiolondra
Copy link

radiolondra commented May 20, 2021

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;

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant