-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from tdameros/pong-server-docker
Pong servers can now run in docker
- Loading branch information
Showing
9 changed files
with
91 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 10 additions & 18 deletions
28
...erver/src/game_server/print_server_uri.py → ..._server/src/game_server/get_server_uri.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,21 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
|
||
def get_server_uri(): | ||
command = (f'lsof -a -p {os.getpid()} -i6' | ||
async def get_server_uri(sio, pid): | ||
await sio.sleep(0.1) | ||
""" The async sleep is here so that the server starts before | ||
this function is executed """ | ||
|
||
command = (f'lsof -a -p {pid} -i4' | ||
f" | awk '{{print $9}}'" | ||
f' | tail -n +2') | ||
""" gets all open ipv6 sockets for current process | ||
""" gets all open ipv4 sockets for current process | ||
| gets the column with the uri of the socket | ||
| removes the first line which only contains the name | ||
of the column """ | ||
|
||
port: str = subprocess.check_output(command, shell=True).decode() | ||
if len(port) == 0: | ||
raise Exception('No open ipv6 sockets found') | ||
return f'http://{port if port[-1] != '\n' else port[:-1]}' | ||
|
||
|
||
async def print_server_uri(sio): | ||
await sio.sleep(0.1) | ||
""" The async sleep is here so that the server starts before | ||
this function is executed """ | ||
|
||
print(f'uri: {get_server_uri()}') | ||
""" Do not use logging()! This should always be printed as the redirection | ||
server will read it """ | ||
sys.stdout.flush() | ||
raise Exception('No open ipv4 sockets found') | ||
return f'http://localhost{port if port[-1] != '\n' else port[1:-1]}' | ||
# TODO this only works on localhost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters