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?
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?
Before calling listen you use the bind function to bind the socket to a local address specified in a sockaddr structure
hmm... i'll post a snipet from my HTTP server (under dev - just started two days ago):
.data ?
sa sockaddr_in <?>
.code
...
invoke WSAStartup,02h,addr wsdata
invoke socket,AF_INET,SOCK_STREAM,0
mov hSock,eax
.if eax==INVALID_SOCKET
invoke MessageBox,0,addr ErrMsg,0,0
invoke PostQuitMessage,0
.endif
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
.if eax==SOCKET_ERROR
invoke closesocket,addr sa
invoke MessageBox,0,addr ErrMsg,0,0
.endif
invoke listen,hSock,8
Just a quick note... .
isnt this wrong?
.if eax==SOCKET_ERROR
invoke closesocket,addr sa <----------------
shouldnt it be:
invoke closesocket,hSock
I maybe wrong...im new to this winsock lark....
isnt this wrong?
.if eax==SOCKET_ERROR
invoke closesocket,addr sa <----------------
shouldnt it be:
invoke closesocket,hSock
I maybe wrong...im new to this winsock lark....