Problems with sockets (win32)
-
Hello I've got a client/server application that sends small packets 10-50 bytes. The server, running win2000, uses IOCP and WSARecv + WSASend. The client uses an ownmade socket class also using WSARecv/WSASend and overlapped IO. Both the client/server waits for a Read, handles it and invoked WSARecv again. WSASend is only invoked when something is waiting in the outbuffer. Serverside: The first two transactions are handled ok (both transactions are sent at the same time and is recieved with the same WSARecv). But the second transaction, sent a couple of seconds later, will not be read by the server. The IOCP function gets called by the WSARecv but 0 bytes read are reported. ClientSide: After the last send I do a WSAGetOverlappedResult and it reports that the bytes were sent. I've tried to disable the nagle algorithm and setting SO_SNDBUF + SO_RCVBUF to 0 in the client. I've also tried to set SO_SNDBUF/SO_RCVBUF to zero in the server. client log: Socket(3)(Connect): WSAConnect() OK! Socket(3)(Read): WSARecv Socket(3)(Read): pending read... Send Trans: 0 Send Trans: 2 Socket(3)(Send): New data triggered. Socket(1)(Send): WSASend Socket(3)(Send): Write completed Socket(3)(Read): Read completed. Socket(2)(Read): WSAGetOverlappedResult Recieve, Trans: 0 Socket(2)(Read): 71/71 bytes handled Socket(3)(Read): WSARecv Socket(1)(Read): Completed directly 14 bytes Recieve, Trans: 2 Socket(2)(Read): 14/14 bytes handled Socket(3)(Read): WSARecv Socket(3)(Read): pending read... Send Trans: 3 Socket(3)(Send): New data triggered. Socket(1)(Send): WSASend Socket(3)(Send): Write completed Socket(3)(Read): Read completed. Socket(2)(Read): WSAGetOverlappedResult <- returns 0 bytes serverlog: prio: 1 client: 4 Connect from 127.0.0.1:1201 prio: 1 client: 4 Read -> Incomming bytes: 29 prio: 3 client: 4 Recieve, Trans: 0 prio: 3 client: 4 Send, Trans: 0 prio: 1 client: 4 Send -> WSASend prio: 2 client: 4 Send ->Sent 71/71 bytes. (flags: 0) prio: 3 client: 4 Recieve, Trans: 2 prio: 3 client: 4 Send, Trans: 2 prio: 1 client: 4 Send -> WSASend prio: 2 client: 4 Send ->Sent 14/14 bytes. (flags: 0) prio: 2 client: 4 Read -> 29/29 bytes handled prio: 1 client: 4 Read -> WSARecv prio: 2 client: 4 Read -> Pending read inited prio: 0 client: 4 0 bytes read! prio: 1 client: 4 Read -> aborting, dead or shutting down... What am I doing wrong?
-
Hello I've got a client/server application that sends small packets 10-50 bytes. The server, running win2000, uses IOCP and WSARecv + WSASend. The client uses an ownmade socket class also using WSARecv/WSASend and overlapped IO. Both the client/server waits for a Read, handles it and invoked WSARecv again. WSASend is only invoked when something is waiting in the outbuffer. Serverside: The first two transactions are handled ok (both transactions are sent at the same time and is recieved with the same WSARecv). But the second transaction, sent a couple of seconds later, will not be read by the server. The IOCP function gets called by the WSARecv but 0 bytes read are reported. ClientSide: After the last send I do a WSAGetOverlappedResult and it reports that the bytes were sent. I've tried to disable the nagle algorithm and setting SO_SNDBUF + SO_RCVBUF to 0 in the client. I've also tried to set SO_SNDBUF/SO_RCVBUF to zero in the server. client log: Socket(3)(Connect): WSAConnect() OK! Socket(3)(Read): WSARecv Socket(3)(Read): pending read... Send Trans: 0 Send Trans: 2 Socket(3)(Send): New data triggered. Socket(1)(Send): WSASend Socket(3)(Send): Write completed Socket(3)(Read): Read completed. Socket(2)(Read): WSAGetOverlappedResult Recieve, Trans: 0 Socket(2)(Read): 71/71 bytes handled Socket(3)(Read): WSARecv Socket(1)(Read): Completed directly 14 bytes Recieve, Trans: 2 Socket(2)(Read): 14/14 bytes handled Socket(3)(Read): WSARecv Socket(3)(Read): pending read... Send Trans: 3 Socket(3)(Send): New data triggered. Socket(1)(Send): WSASend Socket(3)(Send): Write completed Socket(3)(Read): Read completed. Socket(2)(Read): WSAGetOverlappedResult <- returns 0 bytes serverlog: prio: 1 client: 4 Connect from 127.0.0.1:1201 prio: 1 client: 4 Read -> Incomming bytes: 29 prio: 3 client: 4 Recieve, Trans: 0 prio: 3 client: 4 Send, Trans: 0 prio: 1 client: 4 Send -> WSASend prio: 2 client: 4 Send ->Sent 71/71 bytes. (flags: 0) prio: 3 client: 4 Recieve, Trans: 2 prio: 3 client: 4 Send, Trans: 2 prio: 1 client: 4 Send -> WSASend prio: 2 client: 4 Send ->Sent 14/14 bytes. (flags: 0) prio: 2 client: 4 Read -> 29/29 bytes handled prio: 1 client: 4 Read -> WSARecv prio: 2 client: 4 Read -> Pending read inited prio: 0 client: 4 0 bytes read! prio: 1 client: 4 Read -> aborting, dead or shutting down... What am I doing wrong?
One thing to make sure with IOCP is that you should make sure the same socket is not serviced by more than one thread at a time otherwise you will have problems. John
-
One thing to make sure with IOCP is that you should make sure the same socket is not serviced by more than one thread at a time otherwise you will have problems. John