![]() |
#2
sweet6hero2013-10-30 11:24
|
from socket import *
from time import ctime
from ftplib import FTP
def runTcp():
host = ""
port = 21567
addr = (host,port)
BUFSIZ = 1024
tcpSock = socket(AF_INET, SOCK_STREAM)
tcpSock.bind(addr)
tcpSock.listen(5)
while True:
tcpCliSock, addr=tcpSock.accept()
print '...connected from:', addr
data = tcpCliSock.recv(BUFSIZ)
if data=="quit":
break
tcpCliSock.send('[%s] %s' % (ctime(), data))
tcpCliSock.close()
tcpSock.close()
def udprun():
host = ""
port = 21567
addr = (host,port)
BUFSIZ = 1024
udpSerSock = socket(AF_INET, SOCK_DGRAM)
udpSerSock.bind(addr)
while True:
print 'waiting for message...'
data, addr = udpSerSock.recvfrom(BUFSIZ)
print 'waiting for message...',addr
udpSerSock.sendto('[%s] %s' % (ctime(), data), addr)
print '...received from and returned to:', addr
if not data:
break
udpSerSock.close()
if __name__ == '__main__':
runTcp()