hi
the socket is returned by accept,
how could i get client's ipaddress from this socket?
thanks
terry
the socket is returned by accept,
how could i get client's ipaddress from this socket?
thanks
terry
you can set the addr parameter of accept to a pointer to an empty sockaddr_in structure. On return this structure contains the IP address (lookup sockaddr or sockaddr_in in the winsock reference).
Thomas
Thomas
hi Thomas
Then,I write to log file on another message proc,I am not sure this addr hasn't been changed, I always think if others connect the server,maybe sockaddr will change.
Is it right?
Terry
.IF ax==FD_ACCEPT
INVOKE accept,listensock,offset sockaddr,sizeof sockaddr
INVOKE WSAAsyncSelect,eax,hwnd,WM_SOCKET,FD_READ or FD_CLOSE
.ELSEIF ax==FD_READ
......................
INVOKE accept,listensock,offset sockaddr,sizeof sockaddr
INVOKE WSAAsyncSelect,eax,hwnd,WM_SOCKET,FD_READ or FD_CLOSE
.ELSEIF ax==FD_READ
......................
Then,I write to log file on another message proc,I am not sure this addr hasn't been changed, I always think if others connect the server,maybe sockaddr will change.
Is it right?
Terry
First of all, this code won't work as the last parameter of accept is a *pointer* to the size of sockaddr, and not the size itself. Use some dword variable, put sizeof sockaddr in it and pass a pointer to that var as parameter for accept.
And yes the address can change as FD_ACCEPT is sent on each request for a connection. You need to handle these requests somehow.
Thomas
And yes the address can change as FD_ACCEPT is sent on each request for a connection. You need to handle these requests somehow.
Thomas
hi Thomas
first, i am sorry i have made same fault twice. :(
Then, I read winsock api ref, Could the function getsockname get client' ip?
thanks
terry
first, i am sorry i have made same fault twice. :(
Then, I read winsock api ref, Could the function getsockname get client' ip?
thanks
terry
Well you could do that to get the address, but you still need some synchronization in your server.
I mean, when you have multiple connections, you have to deal with them seperately and don't get things mixed up.
I don't know what kind of server you are creating but make sure you use the right socket at the right time..
Thomas
I mean, when you have multiple connections, you have to deal with them seperately and don't get things mixed up.
I don't know what kind of server you are creating but make sure you use the right socket at the right time..
Thomas
:)
OK, i will be careful.
you are really patient.
thanks for all
Terry
OK, i will be careful.
you are really patient.
thanks for all
Terry