multiplayer over the network

Find quick help here to get you started with Hollywood
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

multiplayer over the network

Post 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.
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: multiplayer over the network

Post 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.
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

Re: multiplayer over the network

Post 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?
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: multiplayer over the network

Post by lazi »

Or you can set up a listening server at each side.
It really depends on the type of the gameplay.
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

Re: multiplayer over the network

Post 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
p-OS
Posts: 167
Joined: Mon Nov 01, 2010 11:56 pm

Re: multiplayer over the network

Post 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.
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

Re: multiplayer over the network

Post 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
p-OS
Posts: 167
Joined: Mon Nov 01, 2010 11:56 pm

Re: multiplayer over the network

Post 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).
peceha
Posts: 111
Joined: Tue Dec 13, 2016 8:39 am
Location: Poland

Re: multiplayer over the network

Post 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).
User avatar
r-tea
Posts: 133
Joined: Tue Feb 16, 2016 11:48 pm
Location: Zdzieszowice, Poland
Contact:

Re: multiplayer over the network

Post 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.
Post Reply