Commits

Victor Kotseruba committed 2c4742e

makefile and message length limit

Comments (0)

Files changed (2)

 
 usage = """
 Usage:
-    $ python FlSock.py PORT CHANNELS
+    $ python FlSock.py PORT CHANNELS MAX_MESSAGE_LENGTH 
 
 """
 
 
 class FlSockChannel(asynchat.async_chat):
-    
-    def __init__(self, server, sock):
+
+    ac_in_buffer_size = 1024
+    ac_out_buffer_size = 1024
+
+    def __init__(self, server, sock, max_length):
         asynchat.async_chat.__init__(self, sock)
         self.data = ''
         self.state = 1
+        self.max_length = max_length
         self.server = server
         self.flash_ready = True
         self.set_terminator(2)
     
     def collect_incoming_data(self, data):
         self.data = self.data + data
+        if len(self.data) > self.max_length:
+            self.close()
     
     def found_terminator(self):
         if self.state == 1:
     
 class FlSockDispatcher(asyncore.dispatcher):
     
-    def __init__(self, port, channels):
+    def __init__(self, port, channels, max_length):
         asyncore.dispatcher.__init__(self)
+        self.max_length = max_length
         self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
         self.set_reuse_addr()
         self.bind(('', port))
     
     def handle_accept(self):
         conn, addr = self.accept()
-        FlSockChannel(self, conn)
+        FlSockChannel(self, conn, self.max_length)
+
 
 if __name__ == '__main__':
-    if len(sys.argv) != 3:
+    if len(sys.argv) != 4:
         print usage
         sys.exit(-1)
-    s = FlSockDispatcher(int(sys.argv[1]), int(sys.argv[2]))
-    asyncore.loop()
+    s = FlSockDispatcher(*map(int, sys.argv[1:]))
+    asyncore.loop()
+flsock:
+	mxmlc -compiler.optimize -compiler.strict -metadata.creator barbuza -metadata.title FlSock -target-player 9  FlSock.as
+
+clean:
+	rm FlSock.swf
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.