Last active
April 6, 2016 09:36
-
-
Save abhigenie92/3e920dad67954ea33106966b57c60cb2 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
=========================== | |
#stroke_client.py | |
from twisted.internet import protocol | |
class StrokeClient(protocol.Protocol): | |
def connectionMade(self): | |
print "Connected to remote server" | |
def dataReceived(self,data): | |
pass | |
class StrokeCientFactory(protocol.ClientFactory): | |
def buildProtocol(self,data): | |
return StrokeClient(self) | |
======================================================== | |
from stroke_client import StrokeClientFactory | |
from twisted.internet.defer import DeferredQueue | |
from twisted.internet.defer import inlineCallbacks | |
class Someclass: | |
def start_server(self): | |
self.stroke_conn=reactor.connectTCP(server_addr_ip_addr,self.stroke_port,StrokeCientFactory()) | |
self.line_queue = DeferredQueue() # stores the co-ordinates of each stroke and is constantly emptied and | |
def send_data(self): | |
'''this function is a thread which sends data to clients as Queue is filled by the on_move_up function''' | |
while True: | |
data = yield self.line_queue.get() # get data from queue | |
json_data=json.dumps(data) | |
try: | |
self.stroke_conn.transport.write(json_data) | |
except socket.error as e: # | |
traceback.print_exc() | |
def on_touch_up(self, touch): | |
if self.lines: # Checks if lines is not empty | |
self.line_queue.put(self.lines) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment