Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this binding socket:

     Socket mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
     mainSocket.Bind(new IPEndPoint(IPAddress.Parse(""), 0));

And I need to know when an extern client is connected and disconnected from my servicies( ftp, database server, app server, etc).
thank for advance.

What I have tried:

I tried with these methods but, did not work for me.

    mainSocket.BeginConnect(new IPEndPoint(IPAddress.Parse(""), 0), new AsyncCallback(ClientConnected), null);
    mainSocket.BeginDisconnect(true, new AsyncCallback(ClientDisconnected), null);

       private void ClientDisconnected(IAsyncResult ar)
           // here get some client info like Ip

       private void ClientConnected(IAsyncResult ar)
           // here get some client info like Ip
Updated 25-Nov-20 4:18am

1 solution

You got it backwards.

You're trying (somehow) to connect the server to a client. It's the client that makes the initial connection and that needs to poll if it wants to maintain some sort of "long-term" connection.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900