 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Sat Jul 22, 2006 5:21 am Post subject: error reading from socket |
|
|
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
|
Posted: Sat Jul 22, 2006 7:32 am Post subject: Re: error reading from socket |
|
|
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 |
|
 |
|
|
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
|
|