Fork me on GitHub
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) 编辑
posted on 2012-07-09 21:56  HackerVirus  阅读(191)  评论(0编辑  收藏  举报