Networking. (YASD)

Discussions related to programming Transport Empire.
Locked
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Networking. (YASD)

Post 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]
Attachments
network.zip
If you know what to do: compile your own binaries.

If you have no clue: run the .exe files FROM A CONSOLE!
(250.51 KiB) Downloaded 853 times
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4561
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Post by Zuu »

Thanks for breaking the silence. :)

I'd played a bit with the code, but nothing advanced.
User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13237
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

Post by Hyronymus »

Indeed worth a BIG thanks, Hellfire. I think I fall into the category who will run the exe from a console ;).
User avatar
DominionSpy
Tycoon
Tycoon
Posts: 1429
Joined: 03 Oct 2003 23:59
Location: Lancashire, UK
Contact:

Re: Networking. (YASD)

Post 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!
Image
You're saying I'm a Dominion spy, and don't even know it! - Dr. Bashir
That's the Joker in my avatar, not me. No wait it is me.
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post 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...)
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...
Locked

Return to “Transport Empire Coding”

Who is online

Users browsing this forum: No registered users and 1 guest