Created
June 30, 2014 18:04
-
-
Save CORDEA/ee685c0cf4740b60bb8b to your computer and use it in GitHub Desktop.
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
#!/bin/env/python | |
from PodSixNet.Connection import ConnectionListener, connection | |
from time import sleep | |
class NetworkListener(ConnectionListener): | |
def __init__(self, host, port): | |
self.Connect((host, port)) | |
print("Client started") | |
def Network_connected(self, data): | |
print("Connected to the server") | |
self.sendHello() | |
def Network_disconnected(self, data): | |
print("Disconnected from the server") | |
def Network_getHello(self, data): | |
print("network: hello") | |
message = data["message"] | |
print("server message: " + str(message)) | |
self.sendHello() | |
def Network_getBye(self, data): | |
print("network: bye") | |
message = data["message"] | |
print("server message: " + str(message)) | |
self.sendBye() | |
def sendHello(self): | |
sleep(1.0) | |
self.Send({"action": "getHello", "message": "Hello Server!"}) | |
def sendBye(self): | |
self.Send({"action": "getBye", "message": "Bye Server!"}) | |
sleep(1.0) | |
def launch(self): | |
while True: | |
connection.Pump() | |
self.Pump() | |
sleep(0.0001) | |
if __name__=='__main__': | |
address = raw_input("Host:Port : ") | |
if not address: | |
host, port = "localhost", 8000 | |
else: | |
host, port = address.split(":") | |
c = NetworkListener(host, int(port)) | |
c.launch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment