Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple game for 2 to run over network.

Status
Not open for further replies.

beachcomber

Mechanical
Joined
Jan 19, 2005
Messages
1,488
Location
GB
Some time ago I created a simple game for 2 players in VB6.
(basically a VB version of the Connect4 game.)
I no longer have the code so I'm going to re-write it in VB.net but was wondering how to make it playable for 2 users across a network.
It isn't for any commercial gain, just for my own interest and also to help my son into programming - when he leaves school this summer he will go on to start a Software Development course at college in September.

Any help would be appreciated.


bc.
2.4GHz Core2 Quad, 4GB RAM,
Quadro FX4600.

Where would we be without sat-nav?
 
Thanks - I'll have alook on there.

bc.
2.4GHz Core2 Quad, 4GB RAM,
Quadro FX4600.

Where would we be without sat-nav?
 
To setup the network communication you will need to learn socket programming. The network communication would be done through the winsock API. In VB.net the API is exposed through the System.Net.Sockets namespace. Tutorials for the technical details of using the interface can be found on Google.

I suggest using a TCP connection for communication between the 2 computers. I guess you will need you add a setup page to the game where you would enter if the computer is acting as a client or server. The server would listen for a connection request from any other computer. The client would also need to know the IP address of the server computer so it knows where to connect. I think the general rule of thumb is you can use any port number over 50000 for this type of application.

 
There are quite a few comms mechanisms between 2 machines. You could use

1) sockets by UDP. If the packets are small, they normally work fine. Basically you make up your own protocol.
2) sockets by TCP - as suggested. Again, you make up your own protocol
3) mailslots - this is a very simple mechanism which is used in the net send command. It is available on all versions of windows so you can even play someone on W3.1! This is similar to sockets but at a slightly higher level and a lot easier to program.
4) RPCs - remote procedure calls. This is fairly complex and not very easy to debug

With 1 & 2, it is no different to sending stuff over a serial port. The thing to note is that if you are testing it on one machine, use a broadcast address (last octet is 255 if it is a LAN) otherwise the packets don't get reflected off the switch and only one app gets to read the traffic. The other alternative is to use multicast.

Not many people know about mailslots. I only stumbled across them by accident 10 years ago - they'd been around for a very long time.

 
Thanks guys, I'll look into these when I finally have time to write the program.

bc.
2.4GHz Core2 Quad, 4GB RAM,
Quadro FX4600.

Where would we be without sat-nav?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top