samedi 28 février 2015

JavaScript wont send

I run the Python Script then run the webpage. I get the following information?



b'GET / HTTP/1.1\r\nOrigin: null\r\nSec-WebSocket-Key: 4seUHkSKT1/gfeLQQCSXjg==\r\nConnection: Upgrade\r\nUpgrade: Websocket\r\nSec-WebSocke'
b't-Version: 13\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko\r\nHost: localhost:9999\r\nCache-Con'
b'trol: no-cache\r\n\r\n'


The python Script is waiting for something else? Why can't I send the string "hi". Why is the word Mozilla in the first bit of information, I don't use it? When I have Python Script connecting to Python Script it sends fine as long as I close the connection on the client side. I have tried many different ways of fixing this, Why can't Python receive the text HI?


Java Script



<title></title>

</head>
<body>
<h1></h1>
<script>
var ws = new WebSocket("ws://localhost:9999/");
ws.send("Hi");
ws.close;

ws.onopen = function() {
document.write("How do I call this function to load this line?")
ws.send("Hello Mr. Server!");

};

ws.onmessage = function (e) { alert(e.data); };

ws.onclose = function() { };



</script>
</body>
</html>


Python Script



import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("", 9999))
sock.listen(5)

import sys


data = []

client, address = sock.accept()


while True:

tmp = client.recv(128)

print(tmp)




Aucun commentaire:

Enregistrer un commentaire