ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My problem definition is ,I have to send a message from one node in a network and it has to be broadcasted to all other nodes in the network.The program what I have given below will be running in all the nodes in the network.The same program should be capable of sending(broadcasting) and receiving. (i.e, there is no separate program for server and client like a chat program).I have written a code but I am not clear with how it has to be done.Kindly help me in this.
I want a single program which will be running in all the nodes in a network(cluster).The program should act as server at broadcasting node and as a client at the receiving node.
It sure would be nice if you would clean up your code. You do know that functions can be created to modularize the code?
As for your code, once again, I do not see how a client on a remote node (host) can connect to this application. Your server has bound its port to 127.0.0.1. This address is not reachable by a remote client application.
You should spend some time getting the fundamentals down before attempting to develop a full-blown application.
For the server:
1. create the socket
2. bind the socket
3. listen on the socket
4. accept client connections
For the client:
1. create the socket
2. connect to the server
I recommend that you write these in two separate files, but if you rather deal with clutter, then place them both in the same file.
Here's a basic server (note, no send/receive is involved):
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.