Posted By


JordanRowles on 04/12/14

Tagged


Statistics


Viewed 106 times
Favorited by 0 user(s)

SocketServer_Server.py


/ Published in: Python
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

URL: SocketServer-Server

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.