GetTriggerUnit-
DogEntrepreneur
- Reaction score
- 129
Ok, so I have a problem. I see the connection message on the server side but not on client side.
I (obviously) use Chrome.
I see the disconnect message (on client side) when I close the server.
Client side:
Server side:
I (obviously) use Chrome.
I see the disconnect message (on client side) when I close the server.
Client side:
Code:
<html>
<head>
<script type="text/javascript" src="../jQuery.js"></script>
<script type="text/javascript">
var ws;
$(document).ready(function () {
ws = new WebSocket('ws://localhost:12615');
ws.onopen = function () {
$('#info').html('<b>Connected</b>');
};
ws.onmessage = function (msg) {
$('#info').html('<b>Message received: </br>' + msg);
};
ws.onclose = function () {
$('#info').html('<b>Disconnected</b>');
};
});
</script>
<div id="info">
</div>
</head>
</html>
Server side:
Code:
package webserver;
import java.net.*;
public class Main {
public static void main(String[] args) throws Exception {
ServerSocket ss = new ServerSocket(12615);
while (true) {
Socket s = ss.accept();
System.out.printf("Connected...\n");
s.getOutputStream().write("Hello!".getBytes());
s.getOutputStream().flush();
System.out.printf("Sent...\n");
}
}
}