Skip to content

Commit b869c18

Browse files
author
parita pooj
committed
for server socket
1 parent a2b7cd2 commit b869c18

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

socket-programming/echo-server.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,29 @@
1010

1111
data ='init'
1212
input_ = [server_socket]
13-
output = []
13+
output = []
14+
name={}
1415

1516
inputready,outputready,exceptready = select.select(input_,output,[])
16-
17-
while 1:
18-
17+
print len(inputready),len(outputready),len(input_),len(output)
18+
while 1:
1919
for s in inputready:
2020
if s==server_socket:
2121
client, address = server_socket.accept()
22-
print "I got a connection from ", address
22+
print "I got a connection from ", address
23+
nick=client.recv(1024)
24+
name[client]=nick
25+
print 'name:',nick
2326
input_.append(client)
2427
output.append(client)
2528
else:
2629
k=s.recv(1024)
2730
if k:
28-
data=data+'\n'+k
29-
if data:
30-
print "received:",data
31-
inputready,outputready,exceptready = select.select(input_,output,[])
32-
33-
34-
inputready,outputready,exceptready = select.select(input_,output,[])
31+
data=data+'\n'+name[s]+':'+k
32+
print data
33+
34+
inputready,outputready,exceptready = select.select(input_,output,[])
35+
3536
for s in outputready:
3637
s.send(data)
3738
data=''

0 commit comments

Comments
 (0)