Created
August 18, 2020 03:14
-
-
Save ppsirg/dadfe879375e0466925e44fcc0313961 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import socket | |
import tornado.gen | |
import tornado.ioloop | |
import tornado.iostream | |
import tornado.tcpserver | |
import tornado.websocket | |
class TcpServer(tornado.tcpserver.TCPServer): | |
@tornado.gen.coroutine | |
def handle_stream(self, stream, address): | |
while True: | |
# va a esperar y va a guardar en el buffer todo lo que llegue hasta que mandes | |
# el caracter \n | |
value = yield stream.read_until('\n') | |
print(value) | |
def main(sockets=None): | |
# configuration | |
host = '0.0.0.0' | |
port = 8008 | |
# tcp server | |
server = TcpServer() | |
server.listen(port, host) | |
print("Listening on %s:%d..." % (host, port)) | |
# infinite loop | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment