List of usage examples for com.google.gwt.corp.websocket WebSocket setListener
public void setListener(Listener listener)
From source file:com.googlecode.gwtquake.shared.client.WebSocketFactoryImpl.java
License:Open Source License
public void send(NetworkAddress adr, byte[] buf, int len) throws IOException { // TODO(haustein): check if addess still matches? if (socket == null) { remotePort = adr.port;// w ww .ja va 2 s . c o m remoteIp = new byte[4]; System.arraycopy(adr.ip, 0, remoteIp, 0, 4); String url = "ws://" + InetAddress.getByAddress(adr.ip).getHostAddress() + ":" + adr.port; System.out.println("connect for send to: " + url); socket = WebSocket.create(url, "" + localPort); System.out.println("socket: " + socket); socket.setListener(new WebSocket.Listener() { public void onOpen(WebSocket socket, OpenEvent event) { connected = true; } public void onMessage(WebSocket socket, MessageEvent event) { String data = event.getData(); msgQueue.add(data); } public void onClose(WebSocket socket, CloseEvent event) { connected = false; } }); } // System.out.println("sending: " + connected+ " " + Lib.hexDump(buf, len, false)); if (connected) { socket.send(Compatibility.bytesToString(buf, len)); } }
From source file:jake2.client.WebSocketFactoryImpl.java
License:Open Source License
public void send(netadr_t adr, byte[] buf, int len) throws IOException { // TODO(haustein): check if addess still matches? if (socket == null) { remotePort = adr.port;//from www . j a v a2 s .c o m remoteIp = new byte[4]; System.arraycopy(adr.ip, 0, remoteIp, 0, 4); String url = "ws://" + InetAddress.getByAddress(adr.ip).getHostAddress() + ":" + adr.port; System.out.println("connect for send to: " + url); socket = WebSocket.create(url, "" + localPort); System.out.println("socket: " + socket); socket.setListener(new WebSocket.Listener() { public void onOpen(WebSocket socket, OpenEvent event) { connected = true; } public void onMessage(WebSocket socket, MessageEvent event) { String data = event.getData(); msgQueue.add(data); } public void onClose(WebSocket socket, CloseEvent event) { connected = false; } }); } // System.out.println("sending: " + connected+ " " + Lib.hexDump(buf, len, false)); if (connected) { socket.send(Compatibility.bytesToString(buf, len)); } }