与python tcp编程控制见
c++ udp/tcp 编程见
server
import socketPORT = 9999BIND_ADDR = ''MAXLINE = 1024buf = []listenfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)listenfd.bind((BIND_ADDR, PORT))while True: buf, client_addr = listenfd.recvfrom(MAXLINE) print 'recieve data from %s: %s' % (client_addr, buf) buf = 'Hello, this is server' listenfd.sendto(buf, client_addr)client
import socketPORT = 9999SADDR = '127.0.0.1'MAXLINE = 1024buf = 'Hello, this is client'sockfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)sockfd.sendto(buf, (SADDR, PORT))buf,server_addr = sockfd.recvfrom(MAXLINE)print 'recieve data from server: %s' % buf
版权声明:本文博主原创文章。博客,未经同意不得转载。