Python Forum
Server infinite loop input from user
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Server infinite loop input from user
#1
I want to server allway ask for input and send to client,now it runs only once. I am using python 2.71. I tried to give some variable and infinite loop while give while x<10, but not working. Where is mistake?

Server
import socket

HOST = '192.168.10.20'                
PORT = 5000     
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
x = 0
while x<10:
   
    x+=1
    data = conn.recv(1024)
    if not data: break
    massage = input('Enter number')
    print "you enter ", massage
    conn.sendall(str(massage))
    conn.sendall(str(data))
   
ΕΎ
#conn.close()
Client
import socket

HOST = '192.168.10.20'
PORT = 5000              
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))


s.sendall('Hello, world')
data = s.recv(1024)
print 'Received', repr(data)



#conn.close()
Desire code is to send from server to clients data and in client i see all output. This is simple code, i will use for some electronics this code, but firstly i must get this done.
Reply
#2
See for a similar problem:
https://python-forum.io/Thread-File-Transfer
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,053 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 907 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,064 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,074 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,082 Dec-11-2022, 07:39 PM
Last Post: snippsat
Shocked Why this code does not go into an infinite loop? 2367409125 2 879 Dec-02-2022, 08:22 PM
Last Post: deanhystad
  Code won't break While loop or go back to the input? MrKnd94 2 946 Oct-26-2022, 10:10 AM
Last Post: Larz60+
Sad how to validate user input from database johnconar 3 1,910 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  Need help with infinite loop & making hotkeys/shortcuts Graxum 1 1,158 Aug-22-2022, 02:57 AM
Last Post: deanhystad
  How to split the input taken from user into a single character? mHosseinDS86 3 1,166 Aug-17-2022, 12:43 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020