我正在尝试使用 Python 实现一个非常基本的类似 Web 服务器的应用程序,这是我当前的代码:
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind(('', serverPort))
serverSocket.listen(1)
print 'Server is now running...'
while 1:
connectionSocket, addr = serverSocket.accept()
connectionSocket.sendall('''
HTTP/1.0 200 OK\r\n
Content-Type:text/html\r\n
Connection:close\r\n
\r\n
<!DOCTYPE html>
<head><title>Lab sign-up - AntonX Server</title></head>
<h1>Lab Sign-up</h1>
<table>
<form action=\"localhost:12000\" method=\"GET\">
<tr><td>Time</td><td>Name</td></tr>
<tr><td>1 PM</td><td><input type=\"text\" name=\"time_1\"></td></tr>
<tr><td>2 PM</td><td><input type=\"text\" name=\"time_2\"></td></tr>
<tr><td>3 PM</td><td><input type=\"text\" name=\"time_3\"></td></tr>
<tr><td>4 PM</td><td><input type=\"text\" name=\"time_4\"></td></tr>
<tr><td>5 PM</td><td><input type=\"text\" name=\"time_5\"></td></tr>
<tr><td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Steal this spot!\"></tr>
</form></table>
</html>\r\n
''')
connectionSocket.close()
问题是...当我导航到 localhost:12000 时,我收到错误 101:连接已重置。这是为什么?