Server/Client-commucation via TCP-Sockets
Hey, there!
Well, I wrote two classes encapsulating socket funcitons of winsock1 (what should run under unix, too). I'm bored of that MS socket stuff. However, the server-application runs as exspected. The client-app's Connect()-function seems to fail, but the running server-app receives the connection. The client's Connect()-functions is implemented as follows: Code:
bool CClient::Connect(std::string strServerIP, unsigned int nPort){ I hope one could help me out. BEst regards, Gary |
First of all, what's the physical relationship
between your client & server? Do they run on the same machine? Can you telnet the box? Cheers, Tink |
I forst wrote the server application. It does run on the same machine and everything works fine if i telnet to my "server". My "client" is compareable to telnet. It should just connect to the server, output every received data and send all input data directly. This is totally protocol-independend.
Again: telneting works fine, but the problem I have on the client side is: connect() fails, but the server receives a connection. But how/why? |
Detect server's disconnection
Well, I figured out that connect() always fails if the unconnected socket is in non-blocking mode. So I set in to non-blocking mode after connection. Now the server-client-connections works all fine except of I have no clue how to recognize the server's disconnection. If the server closes its socket, the non-blocking client still returns -1 on read() meaning no data available. It never returns 0.
On the other hand: if the client closes the connection, the read()-method on the server side returns 0 indicating the client's closure. But that procedure does not work on the client side in case of a server's socket closure :( Maybe there is some bug in my code I do not know about, cause this is my first socket encapsulation. But referring to all used documentation I think it's ok like that... However: if anybody would like to see my code: email me cause my webspace-provider does not support http-downloads :(. Remember: I used winsock1. If you're gonna test it under unix, please include the corresponding headers yourself. Thx. I'd appreciate any kind of constructive critic/help. Gary |
I've been following this nice tutorial on the subject:
http://www.ecst.csuchico.edu/~beej/g....html#blocking You might want to check out that select() function. |
Well, I dont's think that's the answer to my question. My problem is the client announcing a connecton failure but the server recognizes a new connection. That does not have anything to do with checks on data availability.
There are many tutorials on the web but none of 'em tells anything about the descripted behaviour :( So far, Gary |
All times are GMT -5. The time now is 02:40 AM. |