I am working through a simple tutorial for C network programming found here: https://beej.us/guide/bgnet/html/multi/index.html
After reading through it, my plan was to implement a testing client/server program, and then start to play around, modify things, add stuff, etc. I implemented the program found here (the first client/server set dealing with TCP connections): https://beej.us/guide/bgnet/html/multi/clientserver.html
Basically, a "server" runs on one machine, and when the client connects, the server just sends "Hello, world!" This works fine when I run both on the same machine and connect to localhost.
However, I am unable to connect between different machines (tried on both a Debian and OpenBSD server, no iptables/pf rulesets). The connection just times out, and I'm not really sure why. I can ping and ssh into both.
Can anyone, specifically anyone familiar with this tutorial, point me in the right direction?
Edit: no X on servers, so no screenshots, but netstat -tlnp | grep 3490 gives me nothing.
netstat -an shows tcp connection listening on 3490.
Network programming enables processes to communicate with each other over a computer network, but it is a complex task that requires programming with multiple libraries and protocols. With its support for third-party libraries and structured documentation, C is an ideal language to write network programs.
Network Programming involves writing programs that communicate with other. programs across a computer network. There are many issues that arise when doing network programming which do not appear when doing single program applications. However, JAVA makes networking applications simple due to the easy-to-use libraries.
A socket is a communications connection point (endpoint) that you can name and address in a network. Socket programming shows how to use socket APIs to establish communication links between remote and local processes.
I don't see your servinfo being filled any where in the code
// Server should allow connections from any ip address
serv_info.sin_addr.s_addr = INADDR_ANY;
Also you might need to fill family and port
// Fill server's address family
serv_addr.sin_family = AF_INET;
To need more details, here is a working server i wrote on a forum http://forum.codecall.net/topic/63924-a-simple-tcp-server-using-linux-c-api/
Right before if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
print out the value of p->ai_addr
I'd bet it's 127.0.0.1. This would cause communication to work fine on one computer, but not happen anywhere else.
To listen on all interfaces, bind on 0.0.0.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With