-
September 12th, 2017, 03:58 PM
#1
TCP Server programming in C++ & Linux?
Hi
I hope you can help me. I'm used in tcp network programming with C++ & C# in Windows. Now I have to write a program for a raspberry pi and I have no idea where to start. This is my task:
My Raspberry program shall open 2 tcp listener ports. When a client is connecting to one of the 2 ports then it shall receive data and sometimes it shall send back at the same port. When the client disconnects I need to have a message generated and then it shall wait for the next connection request. The very same shall happen with the second socket.
I have already written such software for windows but there I could open 2 sockets and then I had either a delegate for the events (receiving, disconnecting) or some windows messages.
I looked around google but I only found C-like examples which have one main function with an endless loop and the program exits when it disconnects. I'm not a big fan of such loops especially it doesn't seem to work that way with 2 ports at the same time. Is there any other way? Something event driven like I'm used in windows?
-
September 13th, 2017, 02:02 AM
#2
Re: TCP Server programming in C++ & Linux?
boost.asio is a modern and portable c++ solution. If you have no stringent performance requirements, it seems also node.js works on Raspberry for an easier alternative.
Originally Posted by Grit
examples which have one main function with an endless loop and the program exits when it disconnects. I'm not a big fan of such loops especially it doesn't seem to work that way with 2 ports at the same time.
what do you mean ? in the end, any 'event based' system works with an 'endless' loop under the hood ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|