Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23218

Cannot Get another message in Socket Server

$
0
0

When I try To send an message to the server there ıs no problem after 1 message but when ı try to send another it failingbeacuse of that my app is buggy and i dont want that no one wants that.

Client:

import socket as soc# Defining The VariablesHOST = '192.168.0.21'  # DON'T Forget To Change it For your computer's Ip Address.PORT = 1024client_socket = soc.socket()Shutdown_Request = "Request_From_Phone_to_Shutdown"Restart_Request = "Request_From_Phone_to_Restart"client_socket.connect((HOST, PORT))def shutdown_btn(e=None):  # Sending Shutdown Request    client_socket.sendall(Shutdown_Request.encode('utf-8'))    client_socket.close()def restart_btn(e=None):  # Sending Restart Request    client_socket.sendall(Restart_Request.encode('utf-8'))    client_socket.close()

Server:

import socket as socimport osos.system("cls"); os.system("color e"); os.system("title  Server: WakeMate")print("   Server is Running... ")def send_ip_to_client():    passprint(" Warning: u may forget the line of 11")def server_program():    #  getting the hostname.    host = soc.gethostname()    port = 1024  # initiate port no above 1024.    server_socket = soc.socket()  # get instance    server_socket.bind((host, port))  # bind host address and port together    server_socket.listen() # configure how many clients the server can listen to simultaneously    while True:        conn, address = server_socket.accept()  # accept new connection        print(f"Connection from: {address}")        while True:            data_get = conn.recv(1024)            if not data_get:                break            data_convert = data_get.decode('utf-8')            # Print The Message.            print(f"Message from client: {data_convert}")            if data_convert == 'Request_From_Phone_to_Shutdown':                print("Line 33 is missing.")                #os.system("shutdown /s /f /t 0")            elif data_convert == 'Request_From_Phone_to_Restart':                print("Line 36 is missing.")                #os.system("shutdown /r /t 0")        #conn.close()  # close the connectionif __name__ == '__main__':    server_program()

I want to send multiple messages like non stoping


Viewing all articles
Browse latest Browse all 23218

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>