Multiple writes to client socket

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Draper

    #1

    Multiple writes to client socket

    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
  • Keith Thompson

    #2
    Re: Multiple writes to client socket

    daniel.draper@b oxensystems.com (Daniel Draper) writes:[color=blue]
    > I have a written a simple client server app using sockets in c.[/color]
    [snip][color=blue]
    > Any ideas?[/color]

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

    --
    Keith Thompson (The_Other_Keit h) kst-u@mib.org <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.

    Comment

    • Nitin

      #3
      Re: Multiple writes to client socket

      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.

      Comment

      • Peter Nilsson

        #4
        Re: Multiple writes to client socket

        Nitin wrote:[color=blue]
        > What is this sizeof ( buf ) ...[/color]

        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.c om,
        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

        Comment

        Working...