Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 客户端未通过套接字模块连接到服务器_Python_Sockets - Fatal编程技术网

Python 客户端未通过套接字模块连接到服务器

Python 客户端未通过套接字模块连接到服务器,python,sockets,Python,Sockets,我想做点什么,告诉我弟弟从朋友那里回家,因为他总是迟到。我在我们车的wifi上测试了它,但客户端没有连接。我不只是使用了“0.0.0.0”,这正是我发现要尝试的,但它不起作用 编辑:我已经转发了端口* 服务器: from socket import * def listToString(s): str1 = " " return (str1.join(s)) s = socket(AF_INET, SOCK_STREAM) s.bind(('0.0.0

我想做点什么,告诉我弟弟从朋友那里回家,因为他总是迟到。我在我们车的wifi上测试了它,但客户端没有连接。我不只是使用了“0.0.0.0”,这正是我发现要尝试的,但它不起作用

编辑:我已经转发了端口*

服务器:

from socket import *


def listToString(s):
    str1 = " "
    return (str1.join(s))


s = socket(AF_INET, SOCK_STREAM)
s.bind(('0.0.0.0', 6050))
s.listen(1)
clientsocket, address = s.accept()
print(f"Jacob has turned on his computer from the ip address {address}")

while True:
    command = input('> ')
    if command.upper() == 'SHUTDOWN':
        clientsocket.send('shutdown'.encode('utf-8'))

    elif command.upper() == 'ALERT':
        clientsocket.send('alert'.encode('utf-8'))
        response = clientsocket.recv(2048)
        print(f'Jacob > {response.decode("utf-8")}')

    elif 'CMDEXE' in command.upper():
        clientsocket.send(command.encode('utf-8'))

    elif 'CLBL' in command.upper():
        text = input('>> ')
        clientsocket.send(f'clbl {text}'.encode('utf-8'))
        print(f'Jacob > {clientsocket.recv(2048).decode("utf-8")}')
        continue
客户:

from socket import *
from os import *
from tkinter import *


def sendresponse(message):
    s.send(message.encode('utf-8'))
    root.destroy()


def send(message):
    s.send(message.encode('utf-8'))


def listToString(s):
    str1 = " "
    return (str1.join(s))


IP = "(IPV4)"
PORT = 6050

s = socket(AF_INET, SOCK_STREAM)
s.connect((IP, PORT))

while True:
    msg = s.recv(2048)
    if msg.decode('utf-8').upper() == 'SHUTDOWN':
        system('cmd /c "shutdown /s /f /t 0"')

    elif msg.decode('utf-8').upper() == 'ALERT':
        system('TASKKILL /F /IM "Windows10Universal.exe"')
        system('TASKKILL /F /IM "RobloxPlayerBeta.exe"')
        system('TASKKILL /F /IM "chrome.exe"')
        system('TASKKILL /F /IM "Minecraft.Windows.exe"')
        system('TASKKILL /F /IM "Valorant.exe"')
        system('TASKKILL /F /IM "Steam.exe"')
        system('TASKKILL /F /IM "osu!.exe"')
        system('TASKKILL /F /IM "Among Us.exe"')
        root = Tk()
        root.geometry('500x500')
        button1 = Button(root, text='Ok. On my way!', command=lambda: s.send('Ok. On my way!'.encode('utf-8')))
        button2 = Button(root, text='NO!!', command=lambda: s.send('NO!!'.encode('utf-8')))
        label = Label(root, text="JACOB IT IS TIME TO COME HOME!")
        label.pack()
        button1.pack()
        button2.pack()
        root.mainloop()

    elif 'CMDEXE' in msg.decode('utf-8').upper():
        command = msg.decode('utf-8').split(' ')
        command.remove('cmdexe')
        system(listToString(command))

    elif 'CLBL' in msg.decode('utf-8').upper():
        text = msg.decode('utf-8')
        text = text.split(' ')
        text.remove('clbl')
        text = listToString(text)
        root = Tk()
        root.geometry('500x500')
        sendb = Button(root, command=lambda: sendresponse(rese.get()), text='Send')
        rese = Entry(root)
        label = Label(root, text=text)
        label.pack()
        rese.pack()
        sendb.pack()
        root.mainloop()

如果我更改了IP地址,此代码将在我的本地网络上运行。

“我正试图做一些事情,告诉我的兄弟从朋友那里回家,因为他总是迟到。”-这不是对你的程序应该做什么的有用描述。基本上,这里有一个无用的描述,然后是一个未记录的代码转储,其中大部分代码可能与您的问题根本没有关系。如果客户端未连接,则说明给定的服务器IP错误,或者客户端和服务器之间存在不允许连接的情况,如防火墙。问题可能不在您的代码中。要在WAN上连接不同的计算机,您需要使用称为端口转发的方法