Link to home
Start Free TrialLog in
Avatar of SGyves
SGyves

asked on

CSocket Question

Ok...I am trying to understand the DCC SEND specs that I have. However, I am not having any luck. Hopefully someone can help. Here is what I have from the spec document:

      Create a socket, bind it to INADDR_ANY, port 0, and
            make it passive (a listening socket).
      Send the recipient a DCC request via CTCP supplying
            the address and port of the socket. (This
            is ideally taken from the address of the local
            side of the socket which is connected to a
            server. This is presumably the interface on
            the host which is closest to the rest of
            the net, and results in one less routing hop
            in the case of gateway nodes).
      Continue normally until a connection is received.

      On a connection:
      Accept the connection.
      Close the original passive socket.
      Conduct transaction on the new socket.


My questions are this. How do I make a passive socket as described using CSocket? Where does the port come from...why are they suggesting port 0. Why set up a socket to listen...close and open another? Can anyone help make sense of this?
ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shiju_luke
shiju_luke

How do I make a passive socket as described using CSocket?
A passive socket is one that simply listens on the socket.  By creating a socket with SOCK_STREAM as the second parameter (nSocketType) and then calling the Listen method will make it passive.

Where does the port come from...why are they suggesting port 0.
Port 0 is the default.  Setting it to port 0 will force windows sockets to select a port.  This will mean that it will listen to all ports.  Use this when you're not sure what port is going to request a connection.

Why set up a socket to listen...close and open another?
Because you need to listen to the socket first.  Imagine you're waiting for a phone call.  You have to listen to the phone.  When the phone rings, you know someone is there and is trying to reach you.  Then you pick up the phone but the phone is listening for other calls if you have call waiting.  In the same way, you listen on a socket.  When it receives a request, you still need this socket to listen for other requests.  So you open a new socket connection to communicate while the old socket listens for more requests.

I hope this helps.