var ws = new WebSocket("ws://example.com/path", "protocol-name");
var exampleSocket = new WebSocket("wss://localhost:8001", "protocolOne"); exampleSocket.onerror = function(e) { console.log(e); }
if (window.WebSocket) { var ws = new WebSocket("ws://example.com/contextname/push"); ws.onmessage = function(event) { var text = event.data; console.log(text); }; } else { // Bad luck. Browser doesn't support it. Consider falling back to long polling. // See http://caniuse.com/websockets for an overview of supported browsers. // There exist jQuery WebSocket plugins with transparent fallback. }
var websocket = new WebSocket("server address"); websocket.onmessage = function(str) { console.log("Someone sent: ", str); }; // Tell the server this is client 1 (swap for client 2 of course) websocket.send(JSON.stringify({ id: "client1" })); // Tell the server we want to send something to the other client websocket.send(JSON.stringify({ to: "client2", data: "foo" }));
new WebSocket("ws://localhost:8001", "protocolOne");
if ("WebSocket" in window) websocket = new WebSocket("ws://yourDomainNameHere.org/");
connection = new WebSocket("ws://localhost:2005/");
import "dart:html"; main() { var ws = new WebSocket("ws://127.0.0.1:8080/ws"); ws.on.open.add( (a) { ws.send("hello, this is the client"); }); ws.on.message.add( (messsage) { print(message); }); }
var myWebSocket = new WebSocket("ws://example.org"); myWebSocket.send("Hello Web Sockets!"); myWebSocket.close();
var ws=new WebSocket("ws://192.168.3.33:8888/ws"); /* if 192.168.3.33 is the server IP and 8888 is the port, the server is serving on. So object is mapped to r"/ws". so now the server can identify the request */
"use strict"; const WebSocket = require("ws"); let ws = new WebSocket("ws://localhost:8080"); ws.onopen = () => { console.log("opened"); }; ws.onmessage = (m) => { console.log(m.data); }; ws.onclose = () => { console.log("closed"); };
protected override void OnCreate(Bundle bundle) { TextView txt = FindViewById<TextView>(Resource.Id.My); using (var ws = new WebSocket("ws://dragonsnest.far/Laputa")) { ws.OnError += (sender, e) => { txt.Text = e.Message; }; .......... }
var exampleSocket = new WebSocket("ws://www.example.com/socketserver", "protocolOne"); exampleSocket.send("Here's some text that the server is urgently awaiting!"); exampleSocket.onmessage = function (event) { console.log(event.data); }
function connect(){ websocket = new WebSocket("wss://yoursite.com:8080"); //attach event handlers websocket.onmessage = onMessage; } function onMessage(evt){ // do your thing }
var websocket = new WebSocket("server address"); websocket.onmessage = function(message) { console.log("Character sent: ", JSON.parse(message)); }; // somewhere in your code websocket.send(JSON.stringify({ position: 42, character: 'a' }));
if (window.WebSocket) { var ws = new WebSocket("wss://localhost:8181/ContextPath/AdminPush"); ws.onmessage = function (event) { var jsonMsg = event.data; var json = JSON.parse(jsonMsg); var msg=json["jsonMessage"]; if (validmsg[msg] && window[msg]) { var nr = ++jsonMsgNr; jsonMessages[nr] = { jsonMsg:jsonMsg, json:json };
var socket = new WebSocket("ws://javascript.ru/ws"); socket.onmessage = function(event) { if (event.data == "reload") { location.reload(); } };
public static WebSocket newInstance(io.vertx.core.http.WebSocket arg) { return arg != null ? new WebSocket(arg) : null; } }
blob = videoEncoder.compile(); var stream_ws = new WebSocket("ws://localhost/webm"); stream_ws.binaryType = 'arraybuffer'; var fileReader = new FileReader(); var arrayBuffer; fileReader.onload = function() { arrayBuffer = this.result; stream_ws.send(arrayBuffer); } fileReader.readAsArrayBuffer(blob);
var ws = new WebSocket("ws://localhost:8080/WebSockets/example"); alert("Hi"); ws.onopen = function(){ writeToScreen("Web Socket is connected!!" + "<br>"); }; function writeToScreen(message) { var div = document.getElementById('test'); div.insertAdjacentHTML( 'beforeend', message ); }