Aria
2.8.0
|
ArSocket example server programThis is an example to show how to use ArSocket. a server. This is the server program. The client is socketClientExample.cpp
This program opens a server on port 7777. It waits for the client to connect and says hello to the client. It then waits for the client to say hello and then exits.
First run this server program. Then run the client program, socketClientExample, perhaps in a different terminal window. You should see the server accept the connection, send its greeting to the client, recieve a response from the client, and then the connection closes.
This server only accepts one client connection, and then it exits. In practice, most servers would loop, accepting many clients, and simultaneously handling curently open client connections. You can use threads to do that (see ArASyncTask), but ArSocket is not inherently thread-safe, you would also need to use an ArMutex object to protect ArSocket calls.
Also see the ArNetServer to help manage a server, or the ArNetworking library for a more complete networking framework.