CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 1999
    Location
    North Germany
    Posts
    306

    Question 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?

  2. #2
    Join Date
    Oct 2008
    Posts
    1,456

    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.

    Quote Originally Posted by Grit View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured