File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -48,3 +48,6 @@ DigitalClock.py
48
48
49
49
Generate a random password
50
50
GeneratePassword.py
51
+
52
+ ## Script 10 - Simple TCP Chat Server
53
+ server.py - Creates a local server on your LAN for receiving and sending messages!
Original file line number Diff line number Diff line change
1
+ import socket
2
+
3
+ IP = '0.0.0.0'
4
+ PORT = 3000
5
+
6
+ def main ():
7
+ server = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
8
+ server .bind ((IP , PORT ))
9
+
10
+ server .listen (5 )
11
+ print (f'Server is listening on { IP } :{ PORT } ' )
12
+
13
+ while True :
14
+ client , address = server .accept ()
15
+ print (f'Received a connection from { address [0 ]} :{ address [1 ]} ' )
16
+
17
+ data = client .recv (4096 )
18
+ decoded_data = data .decode ()
19
+ print (decoded_data )
20
+
21
+ send = input ('Send message> ' )
22
+ client .send (send .encode ())
23
+
24
+
25
+ if __name__ == '__main__' :
26
+ main ()
You can’t perform that action at this time.
0 commit comments