multiplayer over the network

Find quick help here to get you started with Hollywood

multiplayer over the network

Postby peceha » Wed Aug 30, 2017 4:27 pm

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

Re: multiplayer over the network

Postby lazi » Wed Aug 30, 2017 10:41 pm

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.
User avatar
lazi
 
Posts: 241
Joined: Fri Feb 25, 2011 12:08 am

Re: multiplayer over the network

Postby peceha » Thu Aug 31, 2017 12:03 am

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?
peceha
 
Posts: 87
Joined: Tue Dec 13, 2016 9:39 am
Location: Poland

Re: multiplayer over the network

Postby lazi » Fri Sep 08, 2017 10:52 pm

Or you can set up a listening server at each side.
It really depends on the type of the gameplay.
User avatar
lazi
 
Posts: 241
Joined: Fri Feb 25, 2011 12:08 am

Re: multiplayer over the network

Postby peceha » Mon Sep 11, 2017 4:43 pm

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
peceha
 
Posts: 87
Joined: Tue Dec 13, 2016 9:39 am
Location: Poland

Re: multiplayer over the network

Postby p-OS » Wed Sep 13, 2017 2:51 pm

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.
p-OS
 
Posts: 69
Joined: Tue Nov 02, 2010 12:56 am

Re: multiplayer over the network

Postby peceha » Wed Sep 13, 2017 4:41 pm

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
peceha
 
Posts: 87
Joined: Tue Dec 13, 2016 9:39 am
Location: Poland

Re: multiplayer over the network

Postby p-OS » Wed Sep 13, 2017 5:08 pm

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).
p-OS
 
Posts: 69
Joined: Tue Nov 02, 2010 12:56 am

Re: multiplayer over the network

Postby peceha » Wed Sep 13, 2017 6:11 pm

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

Re: multiplayer over the network

Postby r-tea » Wed Sep 13, 2017 6:37 pm

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.
User avatar
r-tea
 
Posts: 58
Joined: Wed Feb 17, 2016 12:48 am
Location: Zdzieszowice, Poland

Next

Return to Newbie questions

Who is online

Users browsing this forum: No registered users and 3 guests