Skip to content

Commit d89bf0d

Browse files
committed
Socket programming Demo
1 parent ecd4b46 commit d89bf0d

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
lst1 = ["Nishit", "Aryaa", "Roopam","Nishit"]
2+
lst2 = [1,2,3,1]
3+
4+
lst3 = list(zip(lst1,lst2))
5+
print(lst3)
6+
7+
set1 = set(zip(lst1,lst2))
8+
print(set1)
9+
10+
dict1 = dict(zip(lst1,lst2))
11+
print(dict1)
12+
13+
zipp = zip(lst1,lst2)
14+
for (a,b) in zipp:
15+
print(a,b)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import socket
2+
3+
#step 1 - Declare a server socket
4+
s = socket.socket();
5+
print("Socket Created")
6+
7+
#step 2 - bind socket
8+
s.bind(("localhost",9999))
9+
10+
#step 3 - start listening and mention # of connection eg. 3
11+
s.listen(3)
12+
13+
#step 4 wait indefinately for incoming connection
14+
while True:
15+
#step 5, create client socket and store address
16+
c, addr = s.accept()
17+
#step 6 - get data from client
18+
name = c.recv(1024).decode()
19+
20+
print("Client connected, address - ", addr, name)
21+
22+
#step 7 - send data to client
23+
c.send(bytes("Hello " + name,'utf8'))
24+
#step 8 - close connection
25+
c.close()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import socket
2+
3+
#step 1 - create client socket
4+
c= socket.socket()
5+
6+
#step 2 - bind to server socket
7+
c.connect(("localhost",9999))
8+
9+
#step 3 - get data from user
10+
name = input("Enter Name - ")
11+
12+
c.send(bytes(name,'utf8'))
13+
14+
#step 4 - get data from server
15+
print(c.recv(1024).decode())

0 commit comments

Comments
 (0)