• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Need help with networking!

D

Doooooli

Guest
Or well it's just a question really!
I'm using this https://forum.yoyogames.com/index.php?threads/how-to-make-a-multiplayer-platformer.5858/

multiplayer engine and it's working awesome!

I was just wondering how hard it would be to write a code to check whether or not the server is on, if it is on a green dot will show and if it's off a grey dot will show :D

idk how hard it will be, i have contacted the creator aswell, but i just wanted to ask becuase maybe it's not as hard as i think it is!

thx
 
C

Christian

Guest
If the server is over the web you can use http_status before it connects so you can see if it's up or down.
 
C

Christian

Guest
If it's being done in python, you can try this then.
Code:
import httplib
conn = httplib.HTTPConnection("www.python.org")
conn.request("HEAD", "/")
r1 = conn.getresponse()
print r1.status, r1.reason
Hamachi still displays an IP Address correct? (I don't use hamachi so I don't know if it does). If so, you can use that as your URL to check. You can also use an open port checker tool. If the server is running, the port checker will be able to see if the port is open or closed. if it's open, that means it sees the server. If it's closed, it can't see the server.
 
D

Doooooli

Guest
If it's being done in python, you can try this then.
Code:
import httplib
conn = httplib.HTTPConnection("www.python.org")
conn.request("HEAD", "/")
r1 = conn.getresponse()
print r1.status, r1.reason
Hamachi still displays an IP Address correct? (I don't use hamachi so I don't know if it does). If so, you can use that as your URL to check. You can also use an open port checker tool. If the server is running, the port checker will be able to see if the port is open or closed. if it's open, that means it sees the server. If it's closed, it can't see the server.
I don't really know how to fix it! I tried different things :/ i also found that you could use http_get(url) but i couldn't use my IP as an URL :( or maybe i'm just doing everything really bad! Idk, but could you give me an example? If you have the time that is :) thx!
 
C

Christian

Guest
Sorry, I forgot they renamed httplib after python 3. Are you using python 3?
If so, use http.client instead found here
https://hg.python.org/cpython/file/3.4/Lib/http/client.py

Then use
Code:
import client
conn = client.HTTPConnection("forum.yoyogames.com")
conn.request("HEAD", "/")
r1 = conn.getresponse()
print (r1.status, r1.reason)
(If it's coming in over SSL, use this instead)
Code:
import client
conn = client.HTTPSConnection("forum.yoyogames.com")
conn.request("HEAD", "/")
r1 = conn.getresponse()
print (r1.status, r1.reason)
It will return the status. All you would need to do is replace forum.yoyogames.com with the server public IP. These forums are being delivered over a secure network so we use the HTTPS connection here. My console reports 200 OK, and that's what you should be reporting. If you get 301, that's just letting you know it's being redirected.

as for gamemaker, the syntax would be.
http_status("forum.yoyogames.com") then replace forum.yoyogames.com with the server IP.
 
D

Doooooli

Guest
Sorry, I forgot they renamed httplib after python 3. Are you using python 3?
If so, use http.client instead found here
https://hg.python.org/cpython/file/3.4/Lib/http/client.py

Then use
Code:
import client
conn = client.HTTPConnection("forum.yoyogames.com")
conn.request("HEAD", "/")
r1 = conn.getresponse()
print (r1.status, r1.reason)
(If it's coming in over SSL, use this instead)

Code:
import client
conn = client.HTTPSConnection("forum.yoyogames.com")
conn.request("HEAD", "/")
r1 = conn.getresponse()
print (r1.status, r1.reason)
It will return the status. All you would need to do is replace forum.yoyogames.com with the server public IP. These forums are being delivered over a secure network so we use the HTTPS connection here. My console reports 200 OK, and that's what you should be reporting. If you get 301, that's just letting you know it's being redirected.

as for gamemaker, the syntax would be.
http_status("forum.yoyogames.com") then replace forum.yoyogames.com with the server IP.

Yea i'm using IDLE 3.5 :p this is the code:
Code:
import socket
import json
import threading
#Variables
client_list = []
client_data = {}
host = 'myip'
port = 5001
s = socket.socket()
s.bind((host,port))
s.listen(25)
print('Server Started')
def handle(self):
    ping = False
    while True:
        try:
            data = self.recv(1024)
            data = data.decode('utf-8')
            ping = True
            data = json.loads(data)
            client_data[str(self)]['x'] = data['x']
            client_data[str(self)]['y'] = data['y']
            carry = []
            for i in client_list:
                carry.append({'x':client_data[str(i)]['x'],'y':client_data[str(i)]['y']})
            self.send(json.dumps(carry).encode('utf-8'))
            del carry
        except:
            if ping == True:
                try:
                    del client_data[str(self)]
                except KeyError:
                    pass
                client_list.remove(self)
                print('Client Disconnected')
                break
            pass
def server():
    while True:
        c, addr = s.accept()
        print("Connection")
        client_list.append(c)
        client_data[str(c)] = {'x':'-200','y':'-200'}
        threading.Thread(target=handle,args=[c]).start()
threading.Thread(target=server).start()
How would i implent that to work with this? :D
 
C

Christian

Guest
You can try this
Code:
import socket
import json
import threading
import client
#Variables
client_list = []
client_data = {}
host = 'myip'
port = 5001
s = socket.socket()
s.bind((host,port))
s.listen(25)
conn = client.HTTPSConnection("forum.yoyogames.com")
conn.request("HEAD", "/")
r1 = conn.getresponse()
print('Server Started')
print ('Connection to server', r1.status, r1.reason)
def handle(self):
    ping = False
    while True:
        try:
            data = self.recv(1024)
            data = data.decode('utf-8')
            ping = True
            data = json.loads(data)
            client_data[str(self)]['x'] = data['x']
            client_data[str(self)]['y'] = data['y']
            carry = []
            for i in client_list:
                carry.append({'x':client_data[str(i)]['x'],'y':client_data[str(i)]['y']})
            self.send(json.dumps(carry).encode('utf-8'))
            del carry
        except:
            if ping == True:
                try:
                    del client_data[str(self)]
                except KeyError:
                    pass
                client_list.remove(self)
                print('Client Disconnected')
                break
            pass
def server():
    while True:
        c, addr = s.accept()
        print("Connection")
        client_list.append(c)
        client_data[str(c)] = {'x':'-200','y':'-200'}
        threading.Thread(target=handle,args=[c]).start()
threading.Thread(target=server).start()
 
D

Doooooli

Guest
You can try this
Code:
import socket
import json
import threading
import client
#Variables
client_list = []
client_data = {}
host = 'myip'
port = 5001
s = socket.socket()
s.bind((host,port))
s.listen(25)
conn = client.HTTPSConnection("forum.yoyogames.com")
conn.request("HEAD", "/")
r1 = conn.getresponse()
print('Server Started')
print ('Connection to server', r1.status, r1.reason)
def handle(self):
    ping = False
    while True:
        try:
            data = self.recv(1024)
            data = data.decode('utf-8')
            ping = True
            data = json.loads(data)
            client_data[str(self)]['x'] = data['x']
            client_data[str(self)]['y'] = data['y']
            carry = []
            for i in client_list:
                carry.append({'x':client_data[str(i)]['x'],'y':client_data[str(i)]['y']})
            self.send(json.dumps(carry).encode('utf-8'))
            del carry
        except:
            if ping == True:
                try:
                    del client_data[str(self)]
                except KeyError:
                    pass
                client_list.remove(self)
                print('Client Disconnected')
                break
            pass
def server():
    while True:
        c, addr = s.accept()
        print("Connection")
        client_list.append(c)
        client_data[str(c)] = {'x':'-200','y':'-200'}
        threading.Thread(target=handle,args=[c]).start()
threading.Thread(target=server).start()
Okay i'll try that, but what code should i use on Game Maker to show if the server really is on? :D thx also for fast responses :D
 
C

Christian

Guest
For gamemaker place this in the Create Event
Code:
get_url = http_get("https://forums.yoyogames.com"); //This is our URL to get information from
return_http_status = "null"; //Set a default status to null. It will be replaced later.
Then place this in the HTTP Event
Code:
if ds_map_find_value(async_load, "id") == get_url
   {
   if ds_map_find_value(async_load, "status") == 0
      {
return_http_status = ds_map_find_value(async_load, "http_status")
    }
}
Then you can draw the result with the Draw Event
Code:
///Draws our return variables
draw_set_color(c_black);
draw_set_font(font_roboto); //Replace font_roboto with a font on your system
draw_text(x,y,"HTTP Status:"+string(return_http_status))
 
D

Doooooli

Guest
You can try this
Code:
import socket
import json
import threading
import client
#Variables
client_list = []
client_data = {}
host = 'myip'
port = 5001
s = socket.socket()
s.bind((host,port))
s.listen(25)
conn = client.HTTPSConnection("forum.yoyogames.com")
conn.request("HEAD", "/")
r1 = conn.getresponse()
print('Server Started')
print ('Connection to server', r1.status, r1.reason)
def handle(self):
    ping = False
    while True:
        try:
            data = self.recv(1024)
            data = data.decode('utf-8')
            ping = True
            data = json.loads(data)
            client_data[str(self)]['x'] = data['x']
            client_data[str(self)]['y'] = data['y']
            carry = []
            for i in client_list:
                carry.append({'x':client_data[str(i)]['x'],'y':client_data[str(i)]['y']})
            self.send(json.dumps(carry).encode('utf-8'))
            del carry
        except:
            if ping == True:
                try:
                    del client_data[str(self)]
                except KeyError:
                    pass
                client_list.remove(self)
                print('Client Disconnected')
                break
            pass
def server():
    while True:
        c, addr = s.accept()
        print("Connection")
        client_list.append(c)
        client_data[str(c)] = {'x':'-200','y':'-200'}
        threading.Thread(target=handle,args=[c]).start()
threading.Thread(target=server).start()
It crashes when i start it up :/ all i did was change forum.yoyogames.com to my ip, and it just crashes :/ do you know why? :) thx!
 
C

Christian

Guest
Is Gamemaker Crashing or Python? If Python is Crashing, you can try typing in http:// before your IP Address. Most browsers can ignore it but python might not be able to. You can also try moving my code all the way to the bottom of your code. Just so it's separate and will run your entire game, then my code at the very end. Just for troubleshooting.
 
D

Doooooli

Guest
Is Gamemaker Crashing or Python? If Python is Crashing, you can try typing in http:// before your IP Address. Most browsers can ignore it but python might not be able to. You can also try moving my code all the way to the bottom of your code. Just so it's separate and will run your entire game, then my code at the very end. Just for troubleshooting.
It was python who crashed, but now it works with the http://

i do tho get an error when starting it
Server Started
Traceback (most recent call last):
File "C:\Users\mramn\Desktop\server test.py", line 47, in <module>
import client
ImportError: No module named 'client'

but it does not crash :D
 
C

Christian

Guest
Just copy the text and make a new Python document called client.py.

If Gamemaker's returning null, you might have to give it a few seconds to register. The Networking Event has to send information and wait for a reply.
 
D

Doooooli

Guest
Just copy the text and make a new Python document called client.py.

If Gamemaker's returning null, you might have to give it a few seconds to register. The Networking Event has to send information and wait for a reply.
Did copy it and made a client.py but now the Server crashes again :/ the client is unstartable aswell :(
 
D

Doooooli

Guest
Just copy the text and make a new Python document called client.py.

If Gamemaker's returning null, you might have to give it a few seconds to register. The Networking Event has to send information and wait for a reply.
Okay it does not crash now, i fixed that! But it does not show any result, it still says null :(
 
Top