通过套接字将数据从js客户端发送到py服务器不起作用

时间:2017-12-14 11:43:41

标签: javascript python node.js sockets client-server

我试图通过套接字从js向py服务器发送一些数据。

JS客户端:

<script src="/socket.io/socket.io.js"></script>
<script>
    var socket = io.connect('http://localhost:1729');
    socket.send("1234");   
</script>   

Py服务器:

import socket
server_socket4=socket.socket()
server_socket4.bind(('localhost', 1729))
server_socket4.listen(1)
(client_socket,client_adress)=server_socket4.accept()
print client_socket.recv(1024)
server_socket4.close()

它正在打印:

GET /socket.io/?EIO=3&transport=polling&t=M1KiY71 HTTP/1.1
Referer: http://localhost:8000/index.html
Accept: */*
Accept-Language: en-US,en;q=0.7,he;q=0.3
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: localhost:1729
DNT: 1
Connection: Keep-Alive

如何打印&#34; 1234&#34;?

1 个答案:

答案 0 :(得分:0)

您还必须使用Socket io模块进行python ...经典套接字无法正常工作。