Multiple writes to client socket

D

Daniel Draper

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
 
K

Keith Thompson

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

Nitin

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

Peter Nilsson

Nitin said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top