Skip to content

Commit cff474a

Browse files
committed
Add client and server file to the git
1 parent 70304eb commit cff474a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

client.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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())

server.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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()

0 commit comments

Comments
 (0)