LAN Game Networking

I know networking is not an easy thing but what is the easiest way for me to get copies of my game to see each other and communicate?

Basically when the player selects the “LAN Play” option I need the window to display any other instances of my game on the local network. Then one player can select another play and ask them if they want to play against him/her. Or should I have one player be the host and the other join the host?

Networking is all new to me.

I eventually want to incorporate online play but I just want to get the LAN Play part working first before I do something way more advanced.

The easiest way would be to use EasyUDPSocket and AutoDiscovery.

I am aware of them but I am not sure what to do. I looked at the AutoDiscovery Example but I can’t get the send messages part to work. I have no idea what “CODE” means.

Where do you see that in the example? Perhaps you’re looking at an older example.

When you send a message, it has two parts - a command (maybe they used to call this code) which can be anything you want it to be and is meaningful only to your programs, and a text of the message.

I’m using Xojo 2013 r4.1

EasyUDPSocket.SendMessageToIndividual ( IPAddress as String, Command as Integer, Data as String )

Is what it says in the Language Reference.

Right. Command is a value of your making. It can be used to enhance the Data and is meaningful only to code you have written to act on it. You control both sides of the conversation, so use it for whatever you want.

I can’t seem to get the messages part of the AutoDiscovery Example to work. It came with the version of Xojo I am using so I assume it should work.

I have on copy running on my Host machine and another running in a Virtual Machine on the same network. I can have each copy see each other but I can’t send any message from one to the other and vice versa. When I enter a command and a message and click send nothing happens. I don’t even get an error so I don’t know what is going on.

The other thing how would I send variables from one to the other? This is all new to me so I have no clue what to do.

Almost forgot, is there a way to store the AutoDiscovery control in a module so the connection remains open regardless of what window is open until I close the connection?

The problem could be the virtual machine, the server/client should work on the same desktop, also the ip and port need to match

I think your in for a world of pain if you don’t know what your doing, sending text is one thing controlling a game is a totally different thing

Typically a socket sends a message, the server does something and replies that its done then closes, if it doesn’t close it just locks up until the program shuts down, likewise if the message it receives is garbage it can hang indefinitely

I’d stick some try/catch in the sockets script and see if its locking up or a timer to at least close it if nothing happens…

Are there any examples to get me started?

In the communication examples the serversocket client and server examples, you need to build at least one and run them both

Nige, you’re thinking TCP. AutoDiscovery is UDP, very different. But you’re right, the problem is likely with the virtual machine. That can be tricky to set up right. It would be better to try with two physical machines on the LAN.

Yes. Add a property to the module and instantiate/bind it in app.Open.

My suggestion is really look for Einhugur ENET UDP Library. Björn was kind and smart to bring us this really awesome piece of code and is specially intended for games ( ENET is a widely used game UDP library to create multiplayer games ).

Almost all multiplayer games uses RakNet or ENET and both are focused on most aspect about dealing with UDP.

Too bad I don’t have $200 to buy as they don’t offer just the ENET by itself.

Couldn’t I use the AutoDiscovery and use the COMMAND to signify what I want the message to do? When one copy receive a particular COMMAND integer, it goes though a SELECT CASE to find out how to handle the message part. Would that work?

I am making a TCG turn-based card game.

How can I add the Events to the property like Error and ReceiveMessage, etc.?

Use AddHandler to tie the events to methods. http://documentation.xojo.com/index.php/AddHandler

I must be doing it wrong as when I input:

AddHandler ADController.Error, AddressOf ADControllerError

I get a TypeMismatch error.

When I press the Tab key I don’t see the Error Event in the AutoComplete list.

ADControllerError must have a signature like

Sub ADControllerError(ad as AutoDiscovery, n as integer)

Dealing with UDP packets need lots of work. For a TCG turn based card ( like the awesome HearthStone ) I would then suggest to use TCP sockets instead of UDP ones. You don’t need fast updates and the tiny TCP overhead makes your coder life easier as you don’t have deal with lost packets, disconnections, packet ordering, packet protocol, etc.

A REST arch would fit perfectly in this kind of games with JSON or XML as packet format. In fact, many MMORPG (WOW, for instance) use a mixture of both TCP and UDP. UDP is not a must have for multiplayer games, just with some kind of games, like Action RPGs for instance.

Xojo now offers ServerSockets in I think all Xojo editions and they are quite fast and perfect for a turn based game. I’m currently working on a Xojo REST project ( in my case I use a console App, but it’s not required ) and I’m proud of how well it works with tons of concurrent connections.

BTW, you project looks interesting. I always wanted to write a HearthStone clone in Xojo… :slight_smile: