0
영어로 유감이지만 소프트웨어에 문제가 있습니다. 도움이 필요합니다. 하지만 우선, 일부 코드!Python 클라이언트가 서버에 다시 연결하지 않습니다
클라이언트 측 :
if connessione.connect(host, port) == True:
connect = True
print 'connection granted'
else:
connect = False
print 'connection refused'
while 1:
do_some_stuff_with_socket
if connect == False:
if connessione.connect(host, port) == True:
connect = True
서버 측 :(인터넷)
import socket
port = 4000
host = '127.0.0.1'
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((host, port))
server_socket.listen(5)
print "Type 'Q' or 'q' to QUIT"
print "Server Waiting for client on port ", port
while 1:
client_socket, address = server_socket.accept()
print "Connection from ", address
while 1:
server_data = raw_input("--> server: ")
if server_data.lower() == 'q':
client_socket.send(server_data)
client_socket.close()
break
else:
client_socket.send(server_data)
client_data = client_socket.recv(1024)
if client_data.lower() == 'q':
print "Quit from client"
client_socket.close()
break
else:
print "<-- client: ", client_data
break
내가 서버를 분리/재부팅 경우에 발견, 클라이언트가 다시 연결하지 않습니다. 소켓을 닫으려면 .terminate()
및 .close()
메서드를 사용했습니다.
연결을 끊을 때 오류가 발생 했습니까? –
왜 "<- client :", client_data? 인쇄 후에 "중단"합니까? 1을 재실행하지 않는 동안 아웃터를 강요합니다. client_socket, address = server_socket.accept()는 다시 호출되지 않습니다. – DevPlayer
@IT 닌자 : 아니요 .. 오류가 발생하지 않습니다 ... :( – imAlessandro