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.
Suggest you use the web search string "client server socket example in C"
You do not need to simulate a local DNS unless you wish to use hostnames. If you use direct IP addressing, you can just client-server away.
Note that client-server can mean many things.
Are you interested in BSD socket programming and the programming in C for Linux or System-V?
Are you interesting in client-server "application" level programming where it uses communications channels, but is architect such that you have a client user which needs to contact a server for centralized data or access?
Things like UDP are sometimes called connectionless because you don't need to "connect" the socket, or you still can perform this action.
Meanwhile TCP you are required to do actions like connect and listen, and these exact examples are what I'm talking about when I mention a web search.
Start with simple IP-based sockets where the computer simply connects to itself. Learn about the "select()" call where a computer waits for an incoming connection request, and see what it does to respond. Create another program which tries to connect to it and send, of course, "Hello, World!".
Start by grabbing any example anywhere – in your favorite language – study it, and watch it go.
Hi Rmistler, thanks for this: "You do not need to simulate a local DNS unless you wish to use hostnames. If you use direct IP addressing, you can just client-server away."
Yes, DNS is just for hostnames. Sometimes, we think too much ans forget basic things. LOL.
Start with simple IP-based sockets where the computer simply connects to itself. Learn about the "select()" call where a computer waits for an incoming connection request, and see what it does to respond. Create another program which tries to connect to it and send, of course, "Hello, World!".
Start by grabbing any example anywhere – in your favorite language – study it, and watch it go.
Lol, never know about this site: "http://lmgtfy.com"
I couldn't resist. But also, "when the world really is chock-full of examples," it also goes to show that you don't have to imagine that you're starting from scratch on some kind of voyage-of-discovery. Grab something that someone has already done and shamelessly steal from it.
In this case, especially look for "high-level frameworks." Look for someone who has already built(!) the "low-level plumbing" that you imagine that you must now build.
Always remember, today, that "virtually anything that you think that you 'have to write'" has already been written – and it's out there, waiting for you to find it.
Last edited by sundialsvcs; 08-25-2017 at 08:19 PM.
Server program:
It will connect to port 5689, with IP Address of course.
Once connected to port 5689, tell client to display something or execute anything.
Server needs to know the IP Address of the client.
Client program:
Client program must be running.
Client will listen to port 5689.
Once it detects a connection and it knows that it is from the server program.
The client will display, like. "Hello, i'm connected. I own the system"
5689 has to be open if you're doing the testing behind firewall.
But worst if the program is listening on port 80,53 or 443 which is basically open on all networks.
Last edited by JJJCR; 09-10-2017 at 09:29 PM.
Reason: edit
And I guess that it bears repeating ... "do not do a thing already done!"
For instance, surf to https://github.com and search for "linux client server socket example."
Or, how about "client server engine."
Don't waste your time, these days, "figuring out" something, when today you can in a matter of a few seconds lay your hands on a working example ... or a complete prototype that you can quickly adapt to your specific purposes. We have very(!) much to thank the generous people who have given us, free of charge, the product of their ... so that we don't have to do the same.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.