Skip to content
Advertisement

(Socket operation on non socket) error while trying to receive data on a TCP server

What I want to do is send a message (which I type on the terminal) from the client to the server. I’m getting this error on the server when I try to call the recv() function. As you can see, the client doesn’t show errors.

enter image description here

This is the code I’ve written for the server side:

JavaScript

I’m confused because I’m already checking that the socket is created properly. What does “non-socket” refers to?

Advertisement

Answer

You never initialize sockfd_cli. Odds are, it’s zero, and that’s your standard input terminal and not a socket. You need to store the return value from accept in sockfd_cli.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement