Python 输出文件内容到网络端口

$ cat mySocketTest.py

 

import sys
import time
import socket

if __name__ == "__main__":
if len(sys.argv) < 4:
print >> sys.stderr, "Usage: mySocketTest.py <host> <port> <lines-per-second> <files>"
exit(-1)

host = sys.argv[1]
port = int(sys.argv[2])
sleeptime = 1/float(sys.argv[3])
filelist = sys.argv[4:]

mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysocket.bind((host,port))
mysocket.listen(1)

while(1):
   (clientsocket,address) = mysocket.accept()

   for filename in filelist:

       print "Sending",filename

       for line in open(filename):

            print line
            clientsocket.send(line)
            time.sleep(sleeptime)

 

$

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
  • 2021-07-10
  • 2021-09-06
  • 2022-02-10
  • 2021-08-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案