Multiple writes to client socket

Discussion in 'C Programming' started by Daniel Draper, Apr 2, 2005.

  1. Hi,

    I have a written a simple client server app using sockets in c. My
    client code works great for a single send/recv operation but as soon
    as I try to write (send) to the same socket again the server does not
    receive the data.

    My client code looks like this:

    sock = make_socket (PORT);

    for (i = 0; i < 2; i++)
    {
    send(sock, MESSAGE, strlen(MESSAGE) + 1, 0);

    n = recv(sock, buf, sizeof(buf), 0);
    if (n > 0)
    printf("server echoed %s\n", buf);
    }

    close(sock);

    First iteration works, but second fails.

    Any ideas?

    Daniel
     
    Daniel Draper, Apr 2, 2005
    #1
    1. Advertising

  2. (Daniel Draper) writes:
    > I have a written a simple client server app using sockets in c.

    [snip]
    > Any ideas?


    Yes. Try a newsgroup specific to your operating system (perhaps
    comp.unix.programmer).

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Apr 2, 2005
    #2
    1. Advertising

  3. Daniel Draper

    Nitin Guest

    What is this sizeof ( buf ).. it might be that sizeof(buf) is much
    larger than strlen(MESSAGE) so it might be w8ing to read sizeof(buf)
    from the the socket.
     
    Nitin, Apr 4, 2005
    #3
  4. Nitin wrote:
    > What is this sizeof ( buf ) ...


    Who knows? You haven't quoted the message you're replying to,
    so anyone who didn't get the original has NO IDEA what you're
    talking about.

    Since you're using Google, please take notice of...

    'If you want to post a followup via groups.google.com,
    don't use the broken "Reply" link at the bottom of the
    article. Click on "show options" at the top of the
    article, then click on the "Reply" at the bottom of the
    article headers.' - Keith Thompson

    --
    Peter
     
    Peter Nilsson, Apr 4, 2005
    #4
    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. Rhino
    Replies:
    4
    Views:
    738
    Rhino
    Mar 24, 2005
  2. davidcalvin

    Multiple reads and writes with popen?

    davidcalvin, Jul 9, 2008, in forum: C Programming
    Replies:
    0
    Views:
    1,124
    davidcalvin
    Jul 9, 2008
  3. vani
    Replies:
    2
    Views:
    503
  4. Replies:
    3
    Views:
    162
    J. Gleixner
    Oct 22, 2007
  5. Csaba  Gabor

    Client side forced disk writes

    Csaba Gabor, Feb 15, 2011, in forum: Javascript
    Replies:
    3
    Views:
    128
    Bart Van der Donck
    Feb 17, 2011
Loading...

Share This Page