Hi, I've followed Iczelions guide to winsock programming, but I'm still not clear on ports. It covers in depth the use of sockets and connecting to sockets using ports, but it doesn't cover listen() at all.

I've figured out how to use listen, except I don't know how to make it listen to a specific port. How do you do this? If you can call connect with it set to port xxxx how does your server program know to listen on port xxxx?
Posted on 2002-04-14 21:10:53 by Ronin Magus
Before calling listen you use the bind function to bind the socket to a local address specified in a sockaddr structure
Posted on 2002-04-14 21:34:00 by Kudos
hmm... i'll post a snipet from my HTTP server (under dev - just started two days ago):

.data ?
sa sockaddr_in <?>
invoke WSAStartup,02h,addr wsdata
invoke socket,AF_INET,SOCK_STREAM,0
mov hSock,eax
invoke MessageBox,0,addr ErrMsg,0,0
invoke PostQuitMessage,0
invoke htons,80 ;Port 80
mov sa.sin_port,ax
mov sa.sin_family,PF_INET
mov sa.sin_addr,0 ;any interface
invoke WSAAsyncSelect,hSock,hWnd,WM_SOCKET,FD_ACCEPT
invoke bind,hSock,addr sa,sizeof sockaddr_in
invoke closesocket,addr sa
invoke MessageBox,0,addr ErrMsg,0,0
invoke listen,hSock,8
Posted on 2002-04-14 22:46:32 by jademtech
Just a quick note... .

isnt this wrong?
invoke closesocket,addr sa <----------------

shouldnt it be:

invoke closesocket,hSock

I maybe wrong...im new to this winsock lark....
Posted on 2003-03-11 15:44:05 by Lennon