Questions tagged [websocket]

WebSocket is an API built on top of TCP sockets and a protocol for bi-directional, full-duplex communication between client and server without HTTP overhead.

WebSockets (or WebSocket) is an API and a protocol for bi-directional, full-duplex communication over TCP sockets. The WebSockets API was originally part of the HTML5 standard, but it has been split off into a separate W3C standard. The WebSockets protocol is an IETF standard described in RFC 6455.

The WebSockets API has full browser support in Chrome 14, Firefox 6, IE 10 (desktop and mobile), Opera 12.1 (desktop and mobile), Safari 6.0 (desktop and mobile), Android 4.4, Chrome Mobile, and Firefox Mobile. Some older browsers have partial support or can be supported using a Flash based fallback.

WebSockets supports both unencrypted and encrypted connections. Unencrypted connections use the "ws://" URL scheme and default to port 80. Encrypted connections use the "wss://" URL scheme and default to port 443. Encrypted connections use Transport Layer Security (TLS).

Simple WebSockets browser JavaScript example:

if ("WebSocket" in window) {
    var ws = new WebSocket("ws://echo.websocket.org/");
    ws.onopen = function() {
        console.log("WebSockets connection opened");
        ws.send("a test message");
    }
    ws.onmessage = function(e) {
        console.log("Got WebSockets message: " + e.data);
    }
    ws.onclose = function() {
        console.log("WebSockets connection closed");
    }
} else {
    // No native support
}

Useful Links

Books

27923 questions
7
votes
3 answers

'gcc' failed with exit status 1 while trying to install gevent-websocket

I'm trying to install gevent-websocket for Python (http://www.gelens.org/code/gevent-websocket/), but when I run easy_install gevent-websocket I get "command 'gcc' failed with exit status 1". The following is the full output from the…
tgarvz
  • 113
  • 1
  • 5
7
votes
7 answers

How to reconnect after you called .disconnect()

Question: How do you reconnect a client to the server after you have issued a manual .disconnect()? In my current project, I need to disconnect a client from the server when the user log out from the session. I did a socket.disconnect() to do the…
Lionel Chan
  • 7,894
  • 5
  • 40
  • 69
7
votes
2 answers

Using WebSocket for file transfer

One of my university lecturers pointed out that it would be interesting to see WebSockets used for file transfer. I'd imagine it would be possible to decode and encode an image file using base64, however would it be possible to send JavaScript / CSS…
Jack
  • 15,614
  • 19
  • 67
  • 92
7
votes
2 answers

android websocket client timeout

Thanks for reading! Background: I am developing an Android client for a server where the requirement is app that requires continuous exchange of messages back and forth with a WebSockets-based server. Implementation: For the client, I use…
Sagar Hatekar
  • 8,700
  • 14
  • 56
  • 72
7
votes
1 answer

How can I play chunks of a video coming through a HTML5 websocket?

Let's say I have an ogg video. I can play it like that : Now if I managed to stream 1ko chunks base64 encoded of this video through an HTML5 websocket, how could I…
Nolhian
  • 574
  • 2
  • 7
  • 18
7
votes
1 answer

websockets with load balancer scalability

I use a load balancer with my web site. The browser initiates a websocket connection to my app server. Does the open connection consume any resources on the LB or is it direct between the browser and the app server? If there is something open on the…
Yaron Naveh
  • 23,560
  • 32
  • 103
  • 158
7
votes
1 answer

WebSocket listener for Microsoft SQL Database

I am currently working on a project which has to use WebSockets as a way of transferring data to my client. The infrastructure looks like this. Client --> Web Server --> Microsoft SQL Database I think that the most ideal situation would be like…
Ruben Homs
  • 591
  • 1
  • 7
  • 21
7
votes
2 answers

How to implement and communicate via websockets in an iOS-app?

I want to create a simple app which contains a UIWebview. Now I want to communicate via websockets with that page. For example when I click on a button on that page, I want to get some strings from that server, so I can work with that information…
geforce
  • 2,593
  • 3
  • 28
  • 44
7
votes
3 answers

How can I send larger messages over WebSocket?

I am developing a WebSocket server with C# and I noticed that all the messages that coming from the browser (Chrome in that case) using the send() method are 126 chars length max. It happens all the time when I want to send messages larger that 126…
udidu
  • 8,269
  • 6
  • 48
  • 68
7
votes
2 answers

iOS - Websocket close and error events not firing

We are noticing issues with Safari iOS not calling Websocket events when the Websocket connection is lost. Our web application has no clue the Websocket's connection has been lost. On Android devices, as soon as the connection is severed, the close…
Thibs
  • 8,058
  • 13
  • 54
  • 85
7
votes
1 answer

JavaScript and WebSockets: using specific protocol

I'm currently working with WebSockets and a PHP server: it works very well with Google Chrome and Opera, but not with Firefox 6. I think it's due to the protocol version this last uses: I see somewhere that it uses the seventh version, whereas it's…
KorHosik
  • 1,225
  • 4
  • 14
  • 24
7
votes
2 answers

Apollo GraphQL: GraphQLWsLink (Subscriptions) Troubles. Cannot get WebSocket implementation to work w/ Next.js

So I have a GraphQL server that I wrote in Go, following this tutorial pretty closely. I have my front-end written as a Next.js application, and I am currently trying to create a client to connect to my server and even following the subscription…
PapaPete
  • 351
  • 3
  • 12
7
votes
1 answer

How to pass Authentication Header in Flutter WebSocketChannel?

I'm using Flutter web_socket_channel package to communicate with server. The class WebSocketChannel doesn't take a header parameter. factory WebSocketChannel.connect(Uri uri, {Iterable? protocols}) => platform.connect(uri, protocols:…
Haseeb Pavaratty
  • 554
  • 3
  • 17
7
votes
2 answers

PHP Websocket Server hybi10

So Chrome 14 has implemented hybi10 version of websockets. I have a in house program that our company uses via chrome that uses websockets which is broken with this change. Has anyone been successful framing the data using a php server? I am able to…
jivetek
  • 256
  • 2
  • 12
7
votes
1 answer

What means skipNegotiation in SignalR HubConnection?

What is the diference between this.hubConnection = new signalR.HubConnectionBuilder() .withUrl(environment.API_URL + "invoicinghub", { skipNegotiation: true, transport: signalR.HttpTransportType.WebSockets }) …
Santiago Semhan
  • 193
  • 2
  • 9
1 2 3
99
100