Skip to content
Permalink
21efbfd7c0
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
45 lines (39 sloc) 1.24 KB
#!/usr/bin/python
import os
import sys
import socket
import threading
import time
from mysocket import send_message, receive_message
from argparse import ArgumentParser
class Server:
def __init__(self, debug=False):
self.debug = debug
def run_forever(self):
self.debug_print('server hello')
serversocket = socket.socket()
serversocket.bind(('0.0.0.0', 8000))
serversocket.listen(5)
(self.clientsocket, addr) = serversocket.accept()
while True:
response_length = int(receive_message(self.clientsocket))
self.debug_print('server received request')
if response_length == 0:
print "something is wrong?"
break
else:
send_message(self.clientsocket, "-" * response_length)
self.debug_print('server sent response length %d' % response_length)
def debug_print(self, msg):
if self.debug:
print msg
sys.stdout.flush()
if __name__ == '__main__':
try:
Server(debug=False).run_forever()
except Exception as e:
print '----- error in server -----'
print e
import traceback
traceback.print_exc()
sys.stdout.flush()