Page 1 of 2

multiplayer over the network

Posted: Wed Aug 30, 2017 4:27 pm
by peceha
Hello,
I wanted to add another player to my little game but it would be nice to have it over the network - so my question is how to start.

In short:
1. two people start the game on two computers
2. one computer finds the other one so the programs can communicate with each other (by communicate I mean sending sprite position so the movement of both players can be visible on each computers)

If this is possible I think I could find the solution by "hit and miss" method but it would take a long time since I have no idea where to start.

Thanks for any help/suggestion/example in advance.

Re: multiplayer over the network

Posted: Wed Aug 30, 2017 10:41 pm
by lazi
I am not made such code yet, so just guesses.

1. It is a big difference if you want to MP on LAN or over the Internet.

2. If you choose LAN, then the problem much simpler. Choose a port to communicate. Send messages by that port to all of your IP range. The IP with a reply will be your MP partner.

3. Over the Internet, you have to use a server or have to set port forwarding on the routers at each side.

4. Over the Internet you have no guaranteed transfer times.

Re: multiplayer over the network

Posted: Thu Aug 31, 2017 12:03 am
by peceha
Over the Internet would be nice but if that's more problematic than I'll try over the LAN first.
So i means I have to use CreateServer() command on one computer and then OpenConnection() on the other one?

Re: multiplayer over the network

Posted: Fri Sep 08, 2017 10:52 pm
by lazi
Or you can set up a listening server at each side.
It really depends on the type of the gameplay.

Re: multiplayer over the network

Posted: Mon Sep 11, 2017 4:43 pm
by peceha
I do need some help here - just to establish the connection.
I have no idea how network works :D all these servers, ip's and other stuff is just a black magic to me - but I know that once I make the "connection between two hollywood programs I will manege the rest ;)

I run this command on one computer (just removed p_functionHandler and installEventHandler stuff)

Code: Select all

server$=CreateServer(Nil)
a little bit later in the program I have the following:

Code: Select all

DebugPrint(GetLocalIP(serverID,#NETWORKSERVER))
DebugPrint(GetLocalPort(serverID,#NETWORKSERVER))
and the output eg:
0.0.0.0
7316
Now I move to the other computer and write:

Code: Select all

OpenConnection(1,"0.0.0.0",7316)
and I get an error:
cannot assign requested address
Please do not laugh just help :D

Re: multiplayer over the network

Posted: Wed Sep 13, 2017 2:51 pm
by p-OS
Though 0.0.0.0 is a valid IP address, it has a special meaning, It means not only local host but also: only available locally. Thus calling it is only possible from the same machine. If you run your client code on the same computer, you will be successful in connecting. When you try to connect from your second computer to the 1st one (the one running your server), you have to use the address of your 1st computer that it has in the network. Most often it is sth. like 192.168.0.x. Open a Shell on your 1st computer and type ipconfig or ifconfig (depends on the OS used) to find out your network address.

Re: multiplayer over the network

Posted: Wed Sep 13, 2017 4:41 pm
by peceha
Thanks for that answer - that helped me a lot !! - I've connected 2 computers.

Just last one question:
follwing command

Code: Select all

serverId=CreateServer(Nil)
generates a port number - how do I know (being on the client computer) what port that is?
Up to now i used (on the server side):

Code: Select all

DebugPrint(GetLocalPort(serverID,#NETWORKSERVER))
and the resulting number (eg. 5167) )I put into the following command on client computer:

Code: Select all

openConnection(Nil,"192.168.1.4",5167)
Thanks

Re: multiplayer over the network

Posted: Wed Sep 13, 2017 5:08 pm
by p-OS
You cannot. But CreateServer has a 2nd argument. You can set a port number as you wish. (later you can migth want to make it configurable).

Re: multiplayer over the network

Posted: Wed Sep 13, 2017 6:11 pm
by peceha
How could I miss it :o
Thanks !!!

I know I said "last question" but... :D
as you can see on the picture I have my project running on two computers
Image

The problem I'm facing now is .. the speed
Whenever I use arrows to move my hero on the left laptop then the right "freezes" for about 3-5 seconds - it happens because of the following command:

Code: Select all

playerTile=ReceiveData(clientID,#RECEIVELINE)
That whole data I'm sending/receiving is only one number between 0 and 300
Is it always taking so long? The network I'm using is very fast (I think).

Re: multiplayer over the network

Posted: Wed Sep 13, 2017 6:37 pm
by r-tea
I'm not deep into the internet stuff, but maybe you better try an UDP connection instead? Hollywood docs state it's faster, but one has no guarantee the data arrived.