Skip to content

Commit 9ded2c3

Browse files
committed
Modified simple_client
Now it's more descriptive
1 parent 991abb2 commit 9ded2c3

File tree

5 files changed

+50
-35
lines changed

5 files changed

+50
-35
lines changed
File renamed without changes.

simple_client/client.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# client.py
2+
3+
import socket
4+
5+
HOST, PORT = '127.0.0.1', 1400
6+
7+
s = socket.socket(
8+
9+
socket.AF_INET # ADDRESS FAMILIES
10+
#Name Purpose
11+
#AF_UNIX, AF_LOCAL Local communication
12+
#AF_INET IPv4 Internet protocols
13+
#AF_INET6 IPv6 Internet protocols
14+
#AF_APPLETALK Appletalk
15+
#AF_BLUETOOTH Bluetooth
16+
17+
18+
socket.SOCK_STREAM # SOCKET TYPES
19+
#Name Way of Interaction
20+
#SOCK_STREAM TCP
21+
#SOCK_DGRAM UDP
22+
)
23+
s.connect((HOST, PORT))
24+
25+
s.send('Hello World'.encode('ascii'))#in UDP use sendto()
26+
data = s.recv(1024)#in UDP use recvfrom()
27+
28+
s.close()#end the connection
29+
print(repr(data.decode('ascii')))

simple_client/server.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# server.py
2+
3+
import socket
4+
5+
HOST, PORT = '127.0.0.1', 1400
6+
7+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)#refer to client.py
8+
s.bind((HOST, PORT))
9+
s.listen(1)#listen for 1 connection
10+
11+
conn, addr = s.accept()#start the actual data flow
12+
13+
print('connected to:', addr)
14+
15+
while 1:
16+
data = conn.recv(1024).decode('ascii')#receive 1024 bytes and decode using ascii
17+
if not data:
18+
break
19+
conn.send((data + ' [ addition by server ]').encode('ascii'))
20+
21+
conn.close()

simple_client_server/client.py

-14
This file was deleted.

simple_client_server/server.py

-21
This file was deleted.

0 commit comments

Comments
 (0)