File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ # import socket module
2
+ import socket
3
+ # Create a client socket using the python socket module
4
+ clientSocket = socket .socket ()
5
+ # connect with previously created server on specific port number
6
+ clientSocket .connect (('localhost' ,9991 ))
7
+
8
+ # Prompting client for his/her name
9
+ name = input ("Enter your name: " )
10
+ # Send name of client to server
11
+ clientSocket .send (bytes (name ,'utf-8' ))
12
+ # reciving message from server
13
+ print (clientSocket .recv (1024 ).decode ())
Original file line number Diff line number Diff line change
1
+ # Importing socket module of python
2
+ from os import name
3
+ import socket
4
+
5
+ # Creating a socket for server using soket module
6
+ serverSocket = socket .socket ()
7
+ print ("Socket created" )
8
+
9
+ # Binding socket with a port number
10
+ serverSocket .bind (('localhost' ,9991 ))
11
+ # listenting for client to make a request
12
+ serverSocket .listen (1 )
13
+ print ('Waiting for connections' )
14
+
15
+ # listen continiously
16
+ while True :
17
+ # Reciving client soket name and address
18
+ clientSocket , address = serverSocket .accept ()
19
+ name = clientSocket .recv (1024 ).decode ()
20
+ # printing the address of client
21
+ print (f"connected with { name } { address } " )
22
+
23
+ clientSocket .send (bytes (" Hello from server" , 'utf-8' ))
24
+ clientSocket .close ()
You can’t perform that action at this time.
0 commit comments