码迷,mamicode.com
首页 > 编程语言 > 详细

python_socket

时间:2014-10-05 03:11:17      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   sp   div   c   on   log   

# socket_server.py

import socket
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind((‘‘,8089))
while True:
# Receive up to 1,024 bytes in a datagram
data, addr = s.recvfrom(1024)
print "Received:", data, "from", addr

 

# socket_client.py

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
port = 8089
host = "localhost"
while True:
msg = raw_input(Enter message:)
s.sendto(msg, (host, port))

 

python_socket

标签:style   blog   color   os   sp   div   c   on   log   

原文地址:http://www.cnblogs.com/zxlovenet/p/4006637.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!