Skip to content

Instantly share code, notes, and snippets.

@CORDEA CORDEA/client.py
Created Jun 30, 2014

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.