gpt4 book ai didi

android - 无法通过 wifi 连接连接到套接字

转载 作者:行者123 更新时间:2023-11-29 23:19:21 25 4
gpt4 key购买 nike

我无法连接到 Raspberry Pi 3 B+ 上的套接字。这是我做的

  1. 安装并配置了 dnsmasq 和 hostapd
  2. 创建了一个访问点并将静态 ip 分配给 wlano 作为 192.168.4.1 而没有桥接到 lan
  3. 启动了一个 python 脚本来监听端口 8888(正在成功等待连接)
  4. 创建了一个 Android 应用程序以连接到接入点并通过套接字将消息发送到端口 8888 上的 192.168.4.1

当我尝试使用 wlan0 静态 ip,192.168.4.1 连接到套接字时,出现未知主机异常。并且 python 脚本将套接字 ip 打印为 127.0.1.1 我如何运行 Python 脚本来监听 wlan0 IP 而不是 127.0.1.1 这是我从互联网上获得的 Python 脚本

import socket
import sys
from thread import *

HOST = '' # Symbolic name meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'

#Bind socket to local host and port
try:
s.bind((HOST, PORT))
except socket.error as msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()

print 'Socket bind complete'

#Start listening on socket
s.listen(10)
print 'Socket now listening'

#Function for handling connections. This will be used to create threads
def clientthread(conn):
#Sending message to connected client
conn.send('Welcome to the server. Type something and hit enter\n') #send only takes string

#infinite loop so that function do not terminate and thread do not end.
while True:

#Receiving from client
data = conn.recv(1024)
reply = 'OK...' + data
if not data:
break

conn.sendall(reply)

#came out of loop
conn.close()

#now keep talking with the client
while 1:
#wait to accept a connection - blocking call
conn, addr = s.accept()
print 'Connected with ' + addr[0] + ':' + str(addr[1])

#start new thread takes 1st argument as a function name to be run, second is the tuple of arguments to the function.
start_new_thread(clientthread ,(conn,))

s.close()

我以前没有做过任何 Python 编程。所以我必须依赖脚本,它运行良好。

最佳答案

设置

HOST = "192.168.4.1"

在代码中,它应该可以工作。

关于android - 无法通过 wifi 连接连接到套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54677489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com