Search code examples
c++windowsnetwork-programmingserver

How can i send simple text to another computer in c++?


Basically all i want to do is have one exe file, on a main computer (windows), start listening over the net for another exe file on another computer (also windows) to send a simple string of text, in which the main computer will receive the text, display it, and then from there i'll be able to figure out what i want to do with it.


Solution

  • When sending data over a network like so at a low level we use something called sockets to send a TCP message. On Windows the standard API for this is Winsock. On a Unix-based computer like MacOS or Linux you'd use Unix Sockets. I'm much more familiar with Unix sockets than Windows ones so I won't be much help to you on the specifics but the Microsoft docs are generally very informative and should get you started.

    Be warned that low level socket programming is not at all a very beginner-friendly programming paradigm. There are third party higher level APIs for c++ that may be easier to use, but quite honestly for most applications I'd just recommend using Golang or C# (Dotnet) for networking applications as both are very similar in functionality to C++ and have much more intuitive interfaces to send TCP messages over a network built into the language.