zoukankan      html  css  js  c++  java
  • socket python

    python socket

     
    from socket import *
    HOST = 'localhost'
    BUFSIZE = 1024
    PORT = 21567
    def client_socket():
        ADDR = (HOST, PORT)
        tcpclisock = socket(AF_INET, SOCK_STREAM)
        tcpclisock.connect(ADDR)
     
        while True:
            data = raw_input('>')
            if not data:
                break
            tcpclisock.send(data)
            data = tcpclisock.recv(BUFSIZE)
            if not data:
                break
            print(data)
     
        tcpclisock.close()
    if __name__ == '__main__':
        client_socket()
       

      

    TCPserver端代码:

    from socket import *
    from time import ctime
    import threading
    HOST = ''
    PORT = 21567
    BUFSIZE = 1024
    ADDR = (HOST, PORT)
    def server(address, size):
        tcpSerSock = socket(AF_INET, SOCK_STREAM)
        tcpSerSock.bind(address)
        tcpSerSock.listen(5)
     
        while True:
            print("waiting for connecting!")
            tcpcliSock, addr = tcpSerSock.accept()
            print('...connect from:', addr)
     
            while True:
                data = tcpcliSock.recv(size)
            if not data:
                break
                tcpcliSock.send('[%s] %s' % (ctime(), data))
            tcpcliSock.close()
        tcpSerSock.close()
    if __name__ == '__main__':
        threads = []
        for i in range(5):
            ADDR = (HOST, PORT + i)
        t = threading.Thread(target = server, args = (ADDR, BUFSIZE))
        threads.append(t)
        t.start()
     
         

      client端代码:

     
    分类: Originality

    Originality

     
    摘要: """'17*x^2 - 16*|x|*y + 17*y^2 = 225'"""import numpy as npimport matplotlib.pyplot as pltX = np.arange(-5.0, 5.0, 0.1)Y = np.arange(-5.0, 5.0, 0.1)x, y = np.meshgrid(X, Y)f = 17 * x ** 2 - 16 * np.abs(x) * y + 17 * y ** 2 - 225fig = plt.figure()cs = plt.contour(阅读全文
    posted @ 2012-07-09 20:15 1210150341 阅读(182) | 评论 (1) 编辑
     
    摘要: from socket import *HOST = 'localhost'BUFSIZE = 1024PORT = 21567def client_socket(): ADDR = (HOST, PORT) tcpclisock = socket(AF_INET, SOCK_STREAM) tcpclisock.connect(ADDR) while True: data = raw_input('>') if not data: break tcpclisock.send(data) da...阅读全文
    posted @ 2012-05-31 17:31 1210150341 阅读(13) | 评论 (0) 编辑
     
    摘要: Git 在Windows下安装过程详情参见:http://help.github.com/win-set-up-git/首先需要注册注册网站:https://github.com/然后需要一个public key1、在~/.ssh目录下执行2、在本机住创建一个目录(algorithm)3、初始化阅读全文
    posted @ 2012-05-19 19:25 1210150341 阅读(8) | 评论 (0) 编辑
  • 相关阅读:
    go爬虫
    node简单爬虫request简单运用
    Centos7.4安装Mysql5.6
    HTML本地资源读取!
    node-request模块
    react中使用AntDesign库 --- babel-plugin-import 配置
    Django 模型(数据库)
    TypeScript--安装依赖,vscode配置ts自动转换成js文件
    python爬虫
    nodejs爬虫简单实现
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2583727.html
Copyright © 2011-2022 走看看