C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

error reading from socket

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Sat Jul 22, 2006 5:21 am    Post subject: error reading from socket Reply with quote



I am trying to send an integer from Java Client to C++ server. I
figured out how to do the conversion. However, I have a problem reading
from the socket.
This is my code:

int DataInputStream::readInt()//reads one integer from the client
{
int32_t var1;
soc->recv((void*)&var1, 4);
var1 = ntohl(var1);
return var1;
}

I am assuming that I need a loop, but I cannot figure out which one. I
tried all cases that I could imagine, but none of them worked.
I MUST use recv function. Here is how it is defined:

int recv(void *buffer, int bufferLen)
throw(SocketException) {
int rtn;
if ((rtn = ::recv(sockDesc, (raw_type *) buffer, bufferLen, 0)) < 0)
{
throw SocketException("Received failed (recv())", true);
}

return rtn;
}

Any help is appreciated.
Back to top
Ian Collins
Guest





PostPosted: Sat Jul 22, 2006 7:32 am    Post subject: Re: error reading from socket Reply with quote



msosno01 (AT) gmail (DOT) com wrote:
Quote:
I am trying to send an integer from Java Client to C++ server. I
figured out how to do the conversion. However, I have a problem reading
from the socket.

What is your problem and where are your tests?

Quote:
This is my code:

int DataInputStream::readInt()//reads one integer from the client
{
int32_t var1;
soc->recv((void*)&var1, 4);
var1 = ntohl(var1);
return var1;
}

I am assuming that I need a loop, but I cannot figure out which one. I
tried all cases that I could imagine, but none of them worked.
I MUST use recv function. Here is how it is defined:

A loop for what?


Quote:
int recv(void *buffer, int bufferLen)
throw(SocketException) {

Exception specifications (other than throw()) tend to be more of
hindrance than a help. Consider what happens if another exception gets
throw.

Quote:
int rtn;
if ((rtn = ::recv(sockDesc, (raw_type *) buffer, bufferLen, 0)) < 0)
{
throw SocketException("Received failed (recv())", true);
}

return rtn;
}

Any help is appreciated.



--
Ian Collins.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.