Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > error reading from socket

Reply
Thread Tools

error reading from socket

 
 
msosno01@gmail.com
Guest
Posts: n/a
 
      07-22-2006
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.

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      07-22-2006
wrote:
> 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?

> 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?

> 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.

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments