error reading from socket

Discussion in 'C++' started by msosno01@gmail.com, Jul 22, 2006.

  1. Guest

    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.
     
    , Jul 22, 2006
    #1
    1. Advertising

  2. Ian Collins Guest

    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.
     
    Ian Collins, Jul 22, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laszlo Nagy
    Replies:
    1
    Views:
    5,019
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    1,015
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    585
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Replies:
    0
    Views:
    702
    Steve Holden
    Feb 1, 2009
  5. Steve Holden
    Replies:
    1
    Views:
    747
Loading...

Share This Page