Posted By

JordanRowles on 04/12/14


Tagged

data socket server SocketServer


Versions (?)

SocketServer_Server.py


 / Published in: Python
 

URL: SocketServer-Server

A server that receives information from programs (Name, DateTime, LogType, Data) and writes it to a file with the syntax: LogFile{programname}_{ISO-Date}.log

  1. # SocketServer_Server.py
  2. # Version: 1.0
  3. # Use: Internal Application (Work)
  4. # Purpose: To log information to files from programs running on machines within the
  5. # network; but are not directly connected to each other.
  6. # Copyright (C)2014 Jordan Rowles
  7. # GNU General Public License Version 3 or Later
  8.  
  9. import SocketServer
  10.  
  11. class myTCPHandler(SocketServer.BaseRequestHandler):
  12. def handle(self):
  13. # self.request is the TCP socket connected to the client
  14. self.data = self.request.recv(1024).strip()
  15. print "{} Wrote:".format(self.client_address[0])
  16. print self.data
  17. self.request.sendall(self.data.upper())
  18.  
  19. if __name__ == '__main__':
  20. HOST, PORT = "localhost", 9999
  21. server = SocketServer.TCPServer((HOST, PORT), myTCPHandler)
  22. server.serve_forever() # Interruptable with Ctrl-C

Report this snippet  

You need to login to post a comment.