mirror of
https://github.com/wassname/pyreadline.git
synced 2026-07-19 11:27:06 +08:00
57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
#*****************************************************************************
|
|
# Copyright (C) 2006 Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
|
|
#
|
|
# Distributed under the terms of the BSD License. The full license is in
|
|
# the file COPYING, distributed as part of this software.
|
|
#*****************************************************************************
|
|
import cPickle
|
|
import logging
|
|
import logging.handlers
|
|
import SocketServer
|
|
import struct,socket
|
|
|
|
try:
|
|
import msvcrt
|
|
except ImportError:
|
|
msvcrt=None
|
|
print "problem"
|
|
|
|
|
|
port=logging.handlers.DEFAULT_TCP_LOGGING_PORT
|
|
host='localhost'
|
|
|
|
def check_key():
|
|
if msvcrt is None:
|
|
return False
|
|
else:
|
|
if msvcrt.kbhit()!=0:
|
|
q=msvcrt.getch()
|
|
return q
|
|
return ""
|
|
|
|
|
|
singleline=False
|
|
|
|
def main():
|
|
print "Starting TCP logserver on port:",port
|
|
print "Press q to quit logserver", port
|
|
print "Press c to clear screen", port
|
|
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
|
|
|
s.bind(("",port))
|
|
s.settimeout(1)
|
|
while 1:
|
|
try:
|
|
data, addr=s.recvfrom(100000)
|
|
print data,
|
|
except socket.timeout:
|
|
key=check_key().lower()
|
|
if "q"==key:
|
|
print "Quitting logserver"
|
|
break
|
|
elif "c" == key:
|
|
print "\n"*100
|
|
|
|
if __name__ == "__main__":
|
|
main() |