Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################################################################################
- #TCPserver.py
- #!/usr/bin/python
- import socket
- s = socket.socket()
- port = 11111
- s.bind(('', port))
- s.listen(5)
- while True:
- c, addr = s.accept()
- data=c.recv(1024)
- print ('Address:',addr,'Data:',data)
- mylist=list(data.split(':'))
- intlist=list()
- for i in range(0,len(mylist)):
- intlist.append(int(mylist[i]))
- intlist.sort()
- c.send(str(intlist))
- c.close()
- #######################################################################################################
- #TCPclient.py
- #!/usr/bin/python
- import sys
- import socket
- arglen=len(sys.argv)
- if arglen<3:
- print('please run as python TCPclient.py <ip_address> <numbers>')
- exit()
- data=str()
- data=data+str(sys.argv[2])
- for i in range(3,arglen):
- data=data+':'+str(sys.argv[i])
- s = socket.socket()
- port = 11111
- s.connect((sys.argv[1], port))
- s.send(data)
- print s.recv(1024)
- s.close
- #######################################################################################################
- #UDPserver.py
- #!/usr/bin/python
- import socket
- s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
- s.bind(('',22222))
- while True:
- data,addr=s.recvfrom(1024)
- print('Address:',addr,'Data:',data)
- mylist=list(data.split(':'))
- intlist=list()
- for i in range(0,len(mylist)):
- intlist.append(int(mylist[i]))
- intlist.sort()
- s.sendto(str(intlist),addr)
- #######################################################################################################
- #UDPclient.py
- #!/usr/bin/python
- import socket
- import sys
- arglen=len(sys.argv)
- if arglen<3:
- print('please run as python UDPclient.py <ip_address> <numbers>')
- exit()
- s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
- port=22222
- addr=sys.argv[1]
- data=str()
- data=data+sys.argv[2]
- for i in range(3,len(sys.argv)):
- data=data+':'+sys.argv[i]
- s.sendto(data,(addr,port))
- data,addr=s.recvfrom(1024)
- print data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement