File tree 5 files changed +50
-35
lines changed
5 files changed +50
-35
lines changed File renamed without changes.
Original file line number Diff line number Diff line change
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' )))
Original file line number Diff line number Diff line change
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 ()
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments