Socket.io-client cannot connect to server using websocket transport - node.js

I'm developing a socket.io Server in Node.js. To test it, I am developing a set of integration tests using Jest. Each test establishes a connection to my local Socket.io Server, however, I am unable to require that the transport is 'websocket'.
I know that my Socket.io Server supports the websocket transport, as it I demonstrate when the browser connects to it.
Is there anything different about running the socket.io Client in Node.js that prevents the 'websocket' transport from being used?

Related

why we use socket.io client we can make app with only using via socket.io server?

I having some doubts that:-
what is need to use the socket.io client we can use only the socket.io server to stop refreshing the app.
what is different between the socket.io client and socket.io server.
check this link
socket-io.client is the code for the client-side implementation of socket.io. That code may be used either by a browser client or by a server process that is initiating a socket.io connection to some other server (thus playing the client-side role in a socket.io connection).
A server that is not initiating socket.io connections to other servers would not use this code. This has been made a little more confusing that it probably should be because when using socket.io, it appears that both client and server are using the same socket.io.js file (because they both refer to a file with the same name), but is not actually the case. The server is using a different file than the client.
From the Github page for socket-io.client:
A standalone build of socket.io-client is exposed automatically by the socket.io server as /socket.io/socket.io.js. Alternatively you can serve the file socket.io.js found at the root of this repository.
Keep in mind that there are unique features that belong to client and server so it should not be a surprise that they use some different code. Though they share code for parsing the protocol and things like that, the server has the ability to run a server or hook into an existing web server and it has methods like .join() and .leave() and data structures that keep track of all the connected sockets and is expected to live in the node.js environment. The client has the ability to initiate a connection (send the right http request), do polling if webSockets are not supported, build on a native webSocket implementation if present, etc....

how to resolve socket-io send connect request infinitely?

I'm new in socket-io. socket-io working fine but keep sending connect request infinitely to server.
Here is my client ts :
private url = environment.socketServer;
constructor() { this.socket = io(this.url) }
The usual reason for a socket.io client to try to connect over and over is if the socket.io version on the server and client are not compatible. The client connects, the server finds the version is incompatible and drops the connection and the client then tries to connect again, over and over.
Other possible issues:
Server infrastructure (such as load balancers, proxies, firewalls, etc...) are not properly configured to allow webSocket connections.
You're trying to connect to a cluster, but it isn't configured for sticky connections that will "bind" a socket.io client to the same server.
You're confused about how a socket.io connection starts. It is normal for the client to start with a couple web connections in a row (polling) until it realizes that both sides support a webSocket and then socket.io switches over to webSocket.

websocket server using nodejs+socket.io cannot be connected by tester sites while ws can

I want to create a websocket server. I heard that socket.io is a good choice.
I tried socket.io with nodejs(v4.4.7) (npm install --save socket.io), using its sample server side code. A little confused why the client side code is using "http://" rather than "ws://" protocol, but after I setup a real server for testing, I found both "http//" and "ws//" will work using the official code.
Everything is fine till now. But soon I found I can't establish a connection using third-party online tester sites like:
1. www.websocket.org/echo.html
2. www.blue-zero.com/WebSocket
The connection seemed never established or closed asap connected,
I found "Firefox can't establish a connection to the server at ws://mytestserver:8888/?encoding=text" in Firefox console,
or "WebSocket connection to 'ws://mytestserver:8888' failed: Connection closed before receiving a handshake response" in Chrome console.
At last I changed socket.io to ws (npm install --save ws). using sample code from github.com/websockets/ws. all tester sites worked well.
(Of course, my final purpose is not to make a tester site work. the fact is the websocket lib based on nopoll integrated in my chip has exactly the same behavior as the tester sites.)
Anybody knows the reason why socket.io does not work with 3rd-party clients while ws does? Thanks a lot.
socket.io requires a socket.io server on the server-side end of things. It will not connect to only a webSocket server.
While socket.io uses webSocket as the underlying transport, it adds a layer on top of webSocket to implement a whole bunch of additional features and that requires server-side support for socket.io. So, you can't connect to a plain webSocket server with the socket.io client.
You must match:
webSocket client <==> webSocket server
socket.io client <==> socket.io server

Connect to Socket.io server with standard web-socket client

Is it possible connect to socket.io server with standard web-socket client?
When connecting to socket.io server through socket.io client, Url started with HTTP but for web-socket clients must use ws.
so, if it is possible, how to connect to socket.io server and what is the url for connecting to socket.io server?
socket.io has a protocol on top of webSockets. If you're going to use socket.io on the server side, then you have to use a socket.io-compatible client on the other end.
So, you can't use a plain webSocket client to connect to a socket.io server.
The socket.io protocol is here.

Are there any Node WebSocket Server javascript client libraries?

I'm using the node WebSocket Server ( http://static.brandedcode.com/nws-docs/ ) in nodejs for websockets and one java client using this websocket client https://github.com/TooTallNate/Java-WebSocket. I couldn't use socket.io as a server because i couldn't find any java clients for it. Now i've searched for a javascript client for Websocket server, and can't find any. Anyone know of any generic web socket clients in javascript? The socket.io client is not connecting to this server. Thanks for any help.
javascript client for Websocket server
It's called window.WebSocket.
If you want fallbacks and browser support (The thing socket.io is good at!)
Try
web-socket-js
Atmosphere (A completely different framework)
I couldn't use socket.io as a server because i couldn't find any java clients for it
Read the socket.io source, write a Java WebSocket client for it. It should only be a thin abstraction ontop of your Java-Websocket.
Personal advice is to make Java support socket.io. Although I don't see why your doing Java - node.js communication over websockets instead of tcp or udp. The latter two are probably better

Resources