java.net.SocketException: No available buffer space, wsock connect

B

bigbinc

I am connecting to a java server through winsock client. I get this
message. Any ideas? Here is my recv code.

totalBytesRcvd = 0;
printf("\nReceived: \n");

int _error_ctr = 0; // I hate quitting, error for so many values
then quit

while (totalBytesRcvd < echoStringLen)
{

if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <=
0) {
DieWithError("\n(blbxcode): recv() failed or connection
closed prematurely");

_error_ctr++;

if (_error_ctr > 12)
break;

} // end of the if

totalBytesRcvd += bytesRcvd;
echoBuffer[bytesRcvd] = '\0';
printf(echoBuffer);

} // end of the while

printf("\n");

closesocket(sock);
WSACleanup();
 
S

Sudsy

bigbinc said:
if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <=
0) {

A return of 0 doesn't imply an error. Also, this line is incorrect.
Assuming that you've defined echoBuffer as char [RCVBUFSIZE] then
you should be doing this:

if( ( bytesRcvd = recv( sock, echoBuffer, RCVBUFSIZE -
totalByteRecvd, totalBytesRcvd ) ) < 0 ) {

The number of characters to read is the buffer size LESS the number
of characters you've already read. The offset if also the number of
characters already received.
Finally, what's a C question doing in c.l.java.programmer? And why
am I answering it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top