Page 1 of 1

Networking. (YASD)

Posted: 06 Mar 2006 18:01
by Hellfire
Networking demo. (Yet Another Simple Demo)
  • The server will open port 4000
  • The client will connect to port 4000
  • The server sends a nice message to the client
  • The client displays the message on the console
  • Both programs terminate :D
And best of all: sources are included and it runs both on Linux and Windows.

To compile with MinGW on windows:

g++ -o client.exe client.cpp -lws2_32
g++ -o server.exe server.cpp -lws2_32

To compile on linux:

g++ -o client client.cpp
g++ -o server server.cpp

Enjoy. :)

Why is this usefull? Let's see:[list][*]Activity! There hasn't been any for months.
[*]Cross platform!
[*]The networking threshold is crossed, so we'll never have to look at this problem again.[/list]

Posted: 06 Mar 2006 21:22
by Zuu
Thanks for breaking the silence. :)

I'd played a bit with the code, but nothing advanced.

Posted: 06 Mar 2006 22:40
by Hyronymus
Indeed worth a BIG thanks, Hellfire. I think I fall into the category who will run the exe from a console ;).

Re: Networking. (YASD)

Posted: 08 Mar 2006 19:23
by DominionSpy
Hellfire wrote:Networking demo. (Yet Another Simple Demo)
  • The server will open port 4000
  • The client will connect to port 4000
  • The server sends a nice message to the client
  • The client displays the message on the console
  • Both programs terminate :D
And best of all: sources are included and it runs both on Linux and Windows.
Am I right in saying that this is only if you have MinGW?
If so, this is a great thing to get the project back on track ;), but I would think that we'll have to take out the MinGW dependency asap.
If not, klasse!

Posted: 09 Mar 2006 05:59
by Hellfire
DominionSpy wrote:Am I right in saying that this is only if you have MinGW?
If so, this is a great thing to get the project back on track ;), but I would think that we'll have to take out the MinGW dependency asap.
If not, klasse!
I'm not sure. I've compiled it with MinGW, but I think it will work with MS Visual C++ or some Borland equivalent as well. It might need a few changes but those are just minor things.

In fact, I had to do some strange things to get the networking support to work on both Linux and Windows:

Code: Select all

#ifdef WIN32
  #include <winsock2.h>
#else
  #include <sys/sockets.h>
  #include <arpa/inet.h>

etc.
(Yes, MinGW needs Winsock for IP support...)