浏览器能否与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
相关产品推荐
相关产品推荐

