Yet-another Multiplayer Demo (with capx)

Show us your completed creations made in Construct 2

Post » Mon Aug 20, 2012 1:07 pm

Hi, I have some issues with your modified Socket-IO plugin, the "Send" action and some conditions (such as "on connect") do not seem to work.
I currently use a quick Python server like this :
[code]import socket
import sys

PORT = 9999

handshake = '''
HTTP/1.1 101 Web Socket Protocol Handshake\r\n\
Upgrade: WebSocket\r\n\
Connection: Upgrade\r\n\
WebSocket-Origin: http://localhost:50000\r\n\
WebSocket-Location: ws://localhost:'''+str(PORT)+'''/\r\n\r\n\
'''
handshakeDone = False
data = ""
header = ""

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("", PORT))
sock.listen(5)
print("Listening on port", PORT)

print("Accepting...")
client, address = sock.accept()
print("Client connected.")
while True:
    if not handshakeDone:
        header += client.recv(16).decode()
        if header.find('\r\n\r\n') != -1:
            data = header.split('\r\n\r\n', 1)[1]
            handshakeDone = True
            print("Handshake Done !")
            client.send(handshake.encode())
            print("Handshake sent back to client.")
    else:
            print("Waiting for data...")
            tmp = client.recv(128).decode()
            print("Data received : ",tmp)
            data += tmp;

            validated = []

            msgs = data.split('\xff')
            data = msgs.pop()

            for msg in msgs:
               if msg[0] == '\x00':
                    validated.append(msg[1:])

            for v in validated:
               print(v)
               client.send('\x00' + v + '\xff'.encode())
[/code]
And some events like this (I verified names and conditions etc...)


I can successfully connect to my server (however, the "OnConnect" event does not trigger). But whenever I try to send data to my server, nothing happens on serverside (the socket is still receiving). And when I close the browser I test my layout in, the Python Console gets full of :
[code]Waiting for data...
Data received :

Waiting for data...
Data received :

Waiting for data...
Data received :

Waiting for data...
Data received :

Waiting for data...
Data received :

Waiting for data...
Data received :

etc...[/code]
Any clues to get this problems solved ?
Thanks.OrionPyro2012-08-20 13:08:11
B
21
S
7
G
4
Posts: 10
Reputation: 3,519

Post » Mon Aug 20, 2012 3:32 pm

@juantar

Do you tried your project on an online server ?
I've a small game working perfectly on local network, and i'm trying to put it online, on an ubuntu server (12.04) but i cant connect to the server ... (And ofc I've no error). Other simple node app works perfectly or at least i got the http:// response.
Any idea ?

Ty !
B
39
S
15
G
5
Posts: 295
Reputation: 6,089

Post » Mon Aug 20, 2012 3:39 pm

@OrionPyro

Python isn't my stronger side but here's my two cents:

[QUOTE=OrionPyro]
I can successfully connect to my server (however, the "OnConnect" event does not trigger). But whenever I try to send data to my server, nothing happens on serverside (the socket is still receiving). [/QUOTE]

Not sure about this, sounds like some server side problem, but need more info. i really dont understand the socket is still receiving part.



[QUOTE=OrionPyro]
And when I close the browser I test my layout in, the Python Console gets full of :
[code]Waiting for data...
Data received :

Waiting for data...
Data received :


etc...[/code]
[/QUOTE]

Looks like you didn't handle what happens when a client disconnects, so your server stays in a loop (because of while True:), and goes to else part, prints "waiting for data", Data received : ",tmp,
but tmp is empty.
I think you should end while loop when a client disconnects.
Be nice until it's time to not be nice
B
36
S
9
G
9
Posts: 293
Reputation: 6,652

Post » Mon Aug 20, 2012 4:40 pm

[QUOTE=JohnnySheffield]Not sure about this, sounds like some server side problem, but need more info. i really dont understand the socket is still receiving part.[/QUOTE]Well, it means that the server-side socket is still waiting for data at this line :
[code]tmp = client.recv(128).decode()[/code]But I guess that the "Send" action does not work correctly, since the server-side socket can't receive anything after the handshake. Also, I tried with a regular Python client in order to test, it works well.

[QUOTE=JohnnySheffield]Looks like you didn't handle what happens when a client disconnects, so your server stays in a loop (because of while True:), and goes to else part, prints "waiting for data", Data received : ",tmp,
but tmp is empty.
I think you should end while loop when a client disconnects.
[/QUOTE]However, socket is still in blocking-mode, whatever, it does not seem to be the main problem (I will add thing to manage disconnecting btw)OrionPyro2012-08-20 16:40:53
B
21
S
7
G
4
Posts: 10
Reputation: 3,519

Post » Mon Aug 20, 2012 8:07 pm

When i try simple node.js server everything works fine, so I don't believe that "Send" action does not work correctly.

Also, when I try your server, i get same behavior as you, except when I close the browser I get the following message:
          
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

then i tried bunch of different examples i found on the web, the best one (which nicely prints all the messages received, but still doesen't work) is here:

http://stackoverflow.com/questions/2153294/python-example-of-joes-erlang-websocket-example

so, i believe your current server isn't doing the whole connection/handshake thing properly, and the client and server don't actually connect, although they exchange handshakes.
(this is interesting read: https://github.com/learnboost/socket.io-spec)

i would try this:

http://autobahn.ws/python

or this:

https://github.com/Lawouach/WebSocket-for-Python

or this:

http://code.google.com/p/pywebsocket/


and more info here:

http://en.wikipedia.org/wiki/Comparison_of_WebSocket_implementations
JohnnySheffield2012-08-20 20:27:42
Be nice until it's time to not be nice
B
36
S
9
G
9
Posts: 293
Reputation: 6,652

Post » Mon Aug 20, 2012 9:18 pm

[QUOTE=JohnnySheffield] When i try simple node.js server everything works fine, so I don't believe that "Send" action does not work correctly.

Also, when I try your server, i get same behavior as you, except when I close the browser I get the following message:
          
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

then i tried bunch of different examples i found on the web, the best one (which nicely prints all the messages received, but still doesen't work) is here:

http://stackoverflow.com/questions/2153294/python-example-of-joes-erlang-websocket-example

so, i believe your current server isn't doing the whole connection/handshake thing properly, and the client and server don't actually connect, although they exchange handshakes.
(this is interesting read: https://github.com/learnboost/socket.io-spec)

i would try this:

http://autobahn.ws/python

or this:

https://github.com/Lawouach/WebSocket-for-Python

or this:

http://code.google.com/p/pywebsocket/


and more info here:

http://en.wikipedia.org/wiki/Comparison_of_WebSocket_implementations
[/QUOTE]
I use Python 3.2, that's why I do not use these libraries.
Anyway I'm going to try out this websocket example, and reading more about handshaking.
B
21
S
7
G
4
Posts: 10
Reputation: 3,519

Post » Mon Aug 20, 2012 9:39 pm

hi all,

i dunno how do that:

Array      set value at int(Socket.lastDataElement(1)) to Sprite.UID

can anyone show me pleace?

is in the picture of this fantastic tutorial thank's so much
LimonSpace2012-08-20 21:41:33
B
11
S
5
G
1
Posts: 53
Reputation: 1,633

Post » Mon Aug 20, 2012 10:20 pm

sorry for the post i solved
B
11
S
5
G
1
Posts: 53
Reputation: 1,633

Post » Thu Aug 23, 2012 7:08 pm

hi i try this tut with my construct file a simple ship in a background but i dunno why when i connect my ship the count of ship go over 1000 he put on my background 1 ship every 0.07 second why?
B
11
S
5
G
1
Posts: 53
Reputation: 1,633

Post » Thu Aug 23, 2012 8:36 pm

@LimonSpace : There is one event in the sample file that says "every 0.07", in the sample file it sends the position of the managed player to the server. What actions do you have there?
B
26
S
7
G
3
Posts: 118
Reputation: 4,264

PreviousNext

Return to Completed Creations

Who is online

Users browsing this forum: No registered users and 0 guests