Hi all:

I have successfully opened a socket to a server and trying to send some data vai the send() function. But what surprised me is: WSAGetLastError() returns nothing, which means the data has been sent to the server, however all the data (a string) will only be displayed at the moment I disconnect from the server.
p.s. I do not have access to the server codes, which has been written by someone else in Java.

Any help is deeply appreciated.

If send is successful I think it returns the number of bytes sent at that time. YOu can use that and compare with the number of data bytes you wanted to send to see if an error occured or not. GetLastError or WSAGetLastError is only used to get detailed error information, and not for error checking.

Anyway you are saying that the string is displayed only when you disconnect from the server. Displayed where? in the Client( that is your software ) or in the Server ( Java Software)? If it is the Server software, try appending a NULL, '\0' character to your string and see. Maybe the server is waiting for a NULL character as the data termination to display it. Since disconnecting sends a NULL character it is displaying it at that point.

Hi there:

Thank you for your fast and helpful reply. I managed to get this problem solved. The solution is to add "\r" at the end of the data string to be sent over to the server.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.