Skip to content
Advertisement

Why can’t I send all messages with my server-client model?

I have implemented a simple server-client model to send and print messages between my Raspberry Pi and my laptop on which I run Linux, Ubuntu. Here are the client and then the server code.

JavaScript

And the server code:

JavaScript

I run the server code on my Raspberry Pi and the client code on my laptop. Connection happens successfully but server only prints out the first message I sent and it won’t print the other 10 messages I am trying to send. I would really appreciate any help. Thanks in advance!

Advertisement

Answer

You need to do the accept() outside of the loop:

JavaScript

accept() waits for a new connection to be established, but you already have a connected socket. So this call will block until you establish a new connection to the server.

Advertisement