#-*-coding:utf-8-*-importsocketRECEIVER_ADDRESS='192.168.0.2'#RECEIVER的IPRECEIVER_PORT=8888#RECEIVER侦听的端口classSender():def__init__(self):#创建sockettry:self.sock=so...
# -*- coding: utf-8 -*-
import socket
RECEIVER_ADDRESS = '192.168.0.2'#RECEIVER的IP
RECEIVER_PORT = 8888#RECEIVER侦听的端口
class Sender():
def __init__(self):
#创建socket
try:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error , msg :
print "Failed to create socket."
return
print 'socket created'
self.makePDU()
self.send()
self.sock.close()
def makePDU(self): #本函数生成PDU
self.data='hello!'
print self.data
def send(self):
global data
#使用socket连接RECEIVER
global RECEIVER_ADDRESS
global RECEI