zoukankan      html  css  js  c++  java
  • 2019.10.17beta

    import socket
    import subprocess
    import os
    server = socket.socket()
    
    server.bind(
        ('127.0.0.1',8888)
    )
    
    server.listen(3)
    
    while 1:
        conn ,addr = server.accept()
        print(addr)
    
        while 1 :
            try:
                data = conn.recv(1024).decode('utf8')
                if  data == 'q':
                    break
    
                if len(data) == 0:
                    continue
    
                print(data)
                # conn.send(data.encode('utf8'))
                # res = subprocess.Popen(data,shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
                data=subprocess.Popen(data)
                # stdout = subprocess.PIPE
                out = data.stdout
                conn.send(out.encode('utf8'))
                # os.system(data)
    
    
    
            except Exception as e:
                print(e)
                break
    
        conn.close()
    
    
    ```python
    import socket
    client = socket.socket()
    client.connect(
        ('127.0.0.1', 8888)
    )
    
    while 1 :
        cmd_msg = input('cmd:')
        if cmd_msg == 'q':
            break
        client.send(cmd_msg.encode('utf8'))
    
        data = client.recv(1024).decode('utf8')
        print(data)
    
    
    client.close()
    ```
  • 相关阅读:
    最大流模板
    大数相加
    . Number throry
    掷骰子 dp
    Java常用类库2
    简单注册功能(未连接数据库)
    Java常用类库
    人机猜拳
    租车系统
    Java一些概念
  • 原文地址:https://www.cnblogs.com/agsol/p/11694422.html
Copyright © 2011-2022 走看看