You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

浏览器能否与Raw Socket通信?井字棋作业技术疑问

浏览器能否与基于Raw Socket实现的服务器通信?

我们需要完成一个采用服务器-客户端架构的井字棋游戏作业,教授要求服务器使用层级低于TCP/UDP的Raw Socket实现,客户端为浏览器。这是否可行?

作业说明原本标注使用TCP/IP,但我询问教授后,她明确要求使用更底层的Raw Socket。以下是她提供的TCP服务器示例代码(禁止使用):

# Import the required libraries
from socket import *

# Listening port for the server
serverPort = 12000

# Create the server socket object
serverSocket = socket(AF_INET,SOCK_STREAM)

# Bind the server socket to the port
serverSocket.bind(('',serverPort))

# Start listening for new connections
serverSocket.listen(1)


# For python 2.x use the following syntax for displaying strings:
print 'The server is ready to receive messages'

# For python 3.x use the following syntax for displaying strings:
#print('The server is ready to receive messages')


while 1:
        # Accept a connection from a client
    connectionSocket, addr = serverSocket.accept()

        ## Retrieve the message sent by the client

        # For python 2.x use the following (no need to convert from byte string to unicode):
        sentence = connectionSocket.recv(1024)

        # For python 3.x use the following
        # (explicit conversion from byte string to unicode using .encode() method):
    #sentence = connectionSocket.decode().recv(1024)
    
        #Modify the message
    capitalizedSentence = sentence.upper()

        ## Send the modified message back to the client
    
        # For python 2.x use the following (no need to convert from unicode to byte string):
        connectionSocket.send(capitalizedSentence)

        # For python 3.x use the following
        # (explicit conversion from unicode to byte string using .encode() method):
    #connectionSocket.send(capitalizedSentence.encode())

        # Close the connection
    connectionSocket.close()

教授要求我们实现比该示例更底层的服务器。我查阅资料后发现浏览器似乎无法与Raw Socket通信,但教授称已实现,对此我存在疑问。

内容的提问来源于stack exchange,提问作者James carter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 00:42:37