-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSocket_Server.py
More file actions
33 lines (27 loc) · 862 Bytes
/
Copy pathSocket_Server.py
File metadata and controls
33 lines (27 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# import socket module is an inbuilt
import socket
# To connect with socket
s = socket.socket()
# print this line when socket is successfully created
print("Socket success fully created")
# This is a port it's require to client side connect the server
port = 1234
# Next bind to the port
# we have not typed any ip in the ip field
# instead we have inputted an empty string
# this makes the server listen to requests
# coming from other computers on the network
s.bind(('', port))
# put the socket into listening mode
s.listen(1024)
print("socket is listning")
# a forever loop until we interrupt it or
# an error occurs
while True:
# Establish connection with client.
c, addr = s.accept()
print("got connection from", addr)
output = input("enter")
c.sendall(output.encode('utf-8'))
# Close the connection with client
c.close()