2018-10-28 21:24:41 +00:00
|
|
|
# client.py
|
|
|
|
|
|
|
|
import socket
|
|
|
|
|
|
|
|
HOST, PORT = '127.0.0.1', 1400
|
|
|
|
|
|
|
|
s = socket.socket(
|
|
|
|
|
2018-10-30 13:59:46 +00:00
|
|
|
socket.AF_INET, # ADDRESS FAMILIES
|
2018-10-28 21:24:41 +00:00
|
|
|
#Name Purpose
|
|
|
|
#AF_UNIX, AF_LOCAL Local communication
|
|
|
|
#AF_INET IPv4 Internet protocols
|
|
|
|
#AF_INET6 IPv6 Internet protocols
|
|
|
|
#AF_APPLETALK Appletalk
|
|
|
|
#AF_BLUETOOTH Bluetooth
|
|
|
|
|
|
|
|
|
|
|
|
socket.SOCK_STREAM # SOCKET TYPES
|
|
|
|
#Name Way of Interaction
|
|
|
|
#SOCK_STREAM TCP
|
|
|
|
#SOCK_DGRAM UDP
|
|
|
|
)
|
|
|
|
s.connect((HOST, PORT))
|
|
|
|
|
|
|
|
s.send('Hello World'.encode('ascii'))#in UDP use sendto()
|
|
|
|
data = s.recv(1024)#in UDP use recvfrom()
|
|
|
|
|
|
|
|
s.close()#end the connection
|
|
|
|
print(repr(data.decode('ascii')))
|