Tutorial: Online Multiplayer with PodSixNet

Post your own tutorials, guides and demos.

Post » Sat Jun 25, 2011 2:53 pm

I'm not sure how you are updating your info, but one thing that might help is to do a "SendtoOthers" call versus a "SendtoAll". If one client has already moved and you just need to send that status to the other client (but don't need extra network traffic) you can do a:

[code:2v51d0ib]
# this send to all clients but yourself
def SendToOthers(self, data, player):
for p in self.players:
if p != player:
p.Send(data)
[/code:2v51d0ib]

You call it like(within a Python class):
self._server.SendToOthers(data,self)

From a Python script within Construct...I'm not positive how it would be called without some testing (not sure if it is a number or Class instance address). You can look at the Dungeon Server example from the tut for this.

Not sure though that will solve the problem. Perhaps it is just too much data to be sent during one tick. The myserver calls are asynchronous to Construct events....so Construct isn't going to wait for one call to finish before it does the next action. So Construct is going to loop through all the Units very rapidly firing off a myserver.SendToAll calls almost all at the same time..which might be creating a bottleneck. So maybe there is a way to experiment with breaking up not sending as much data each time or adding a slight pause (Wait plugin?..not sure how buggy it is) after each SendToAll in the "For Each Units" loop. How many units do you have?

As far as a limit: You shouldn't be trying to send more than 1500 bytes at a time (the Maximum Transmission Unit (MTU) over most networks. Although, I would suspect PodSixNet would handle that transparently, but I didn't check.

Give the above a thought and let me know how it goes. :-)
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Mon Jun 27, 2011 4:48 am

There's only one client allowed so that shouldn't matter.  I assumed that it must be the fact that the calls are not waiting for stuff to go through before moving on, and that the client was missing some of the incoming data that way (the server was sending it as I tested, but teh client was not getting it) because it was not waiting for the server's info to all come in, but was instead busy trying to do its own data sending to the server.  

I was able to fix the problem by having the client and server do their networking stuff one at a time, such that they wait for each other to be done with sending stuff stuff before sending their own information.  Since it's a turn-based game this works.  I didn't do this originally because the data sent back and forth was independent and I thought it would be faster to have both client and server send to each other at the same time, but apparently when sending a ton of data that way, it doesn't work.  Still haven't tested it with high latency (ran both server and client on same machine) but it seems all the data is getting transferred now.

I think all of the networking features in my game are working now :)  Thanks again for the help and the amazing tutorial, I didn't think it would only take such a short time to get the multiplayer operational!
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Tue Jun 28, 2011 12:04 am

What's the difference between a TCP protocol module and a UDP one?
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue Jun 28, 2011 11:05 pm

@Juryiel
Glad to hear!

@Guif0DA

TCP is connection oriented, stateful, and reliable. Packets are sequenced and arrive in order. If a packet is dropped by the target computer all other packets must wait in a queue until the dropped one is resent and processed. Thus why TCP is not ideal for fast online games.

UDP is connectionless and unreliable. In the scenario above, UDP would not have a problem as the next packet (technicaly a datagram) would be processed immediately. Most game engines have an additional layer on top of UDP to add some reliability and statefullness, when needed.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Mon Oct 10, 2011 7:59 pm

Hi everyone!
First of all, networking is a new thing for me.

scidave wrote:
"Adding text based online using PodSixNet would be as simple as taking the chat example and expanding it a little bit.
The only part that isn't easy is initiating connections with your opponents. Right now you need a internet facing server (or you have to manually configure port forwarding on your computer)..."

Who need to set up 'port forwarding'? The server, the clients, or both...

What is an 'internet facing server'? (related to construct+PodSixNet)
Do I have to pay for it?

Thanks for reading this post.
B
3
S
1
G
2
Posts: 8
Reputation: 866

Post » Tue Oct 11, 2011 3:57 am

Only the server needs to have port forwarding setup.

An internet facing server is an computer that can be accessed from the internet by IP address or Domain name. It could be your home computer (where you enable port forwarding on your router) or it could be a dedicated server.

You don't need to pay if you want to go the simple port forwarding approach.

Here is a link that shows port forwarding:
http://www.associatedcontent.com/article/1556120/how_to_enable_port_forwarding_on_a.html

B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sun Sep 23, 2012 8:47 pm

Does this work with C2, or just Construct?
B
7
Posts: 19
Reputation: 778

Post » Sun Sep 23, 2012 9:43 pm

@WonkaVee
Just Construct Classic
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Mon Sep 24, 2012 6:02 am

It is pretty interesting though, this makes me want to load up CC and experiment.
Anyone has any brief information on how secure this is? The speed? comparison to other networking sockets etc.
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Mon Oct 22, 2012 4:39 am

Hey Rory,

PodSixNet is fairly efficient since it has a built in encoder/serialization. It is only TCP so isn't going to be useful for shooters or other fast real-time gaming. You can host the server (if you want to only use Python) on any system that supports Python (Linux, Windows, etc).

I'm not sure what you mean by secure..it can be made as secure from cheating based on how much you host on the server and what type of checking you program in.

If you are interested in faster performance look at the Plugin I made as a wrapper around Enet. It is posted in the work in progress plugin section. I will warn you that there are some bugs so it is not as stable as PodSixNet, but it is based on UDP so is much faster. It could be made even faster if compression was added.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

PreviousNext

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 1 guest