I'm currently in the process of creating a game.
Find here: https://docs.google.com/document/d/1zxC9Mo9LtcMf3jXA3z4xdz7Lj3G3EVGA4_CQzjoeyOA/edit?usp=sharing
I'm trying to make it so that I get a message when someone new joins. My current method is having the site connect to my computer through a certain port, which then triggers the following python script:
import discord
import asyncio
import websockets
import threading
f = open('runs.txt', 'r')
runs = int(f.readline())
f.close()
def write(input):
f = open( 'runs.txt', 'w' )
f.write( str(input) )
f.close()
username = '<Bot Username>'
password = '<Bot Password>'
client = discord.Client()
client.login(username, password)
chan = discord.PrivateChannel('<Username>', <Channel ID>)
@asyncio.coroutine
def hello(websocket, path):
global runs
input = yield from websocket.recv()
print(input)
if input == 'started':
runs += 1
write(runs)
client.send_message(chan, 'User has played Daedalus')
start_server = websockets.serve(hello, '<My public IP>', <Forwarded Port>)
@client.event
def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
def on_message(message):
if message.content.lower().startswith('check'):
client.send_message(message.author, 'There are now '+ str(runs) + ' computers that have played daedalus')
def asyncBegin():
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
disco = threading.Thread(target=client.run)
disco.start()
asy = threading.Thread(target=asyncBegin())
asy.start()
This program then uses the online app Discord to send me a message via a bot I created. The text document mentioned is just to keep the number of runs. In the game it is programmed to immediately connect to my public IP with the right port number, which should run the program.
I have found that on on localhost it works fine, but as soon as I try to connect through the web it doesn't work.
When I look at the connection status, it just tries to connect for a bit before closing the connection. I do not have any firewalls or network security up while i'm testing. What could be causing it to disconnect?