step:
start a derby app
write a standalone node client app , set up socket.io-client , connect to derby's store's sockets
questions:
the client is not run at browser, so it don't has session, can it pass Racer's socket authorization?
how to write dery service that can listen message from client, then put it into derby store/model?
You can fallback to ajax by having following in your /server/index.js
require('derby/node_modules/racer').io.set('transports', ['xhr-polling']);
Checkout example
Related
The following code only works in the browser. It does not work in node.js
let socket1 = io('http://localhost:3031/nsp')
socket1.on("connect", (error) => {
console.log("socket1: connect")
});
I am connecting to a netty-socketio (v1.7.7) java server. I am able to connect to the root namespace on both browser and node.js clients and everything works as expected. However, if I try to connect to a namespace, only the browser client can connect as expected.
Furthermore, I can see on the server that the node.js client (v2.4.0) is connecting to the root namespace when it should be connecting to the named namespace "nsp". As such, the clients join the root namespace and seemingly never join the "nsp" namespace.
On further inspection, the only event I can get to fire on the node.js client, when specifying a namespace, after connecting is "ping" all other events (connect,connect_error,error,reconnect...) never trigger.
Update: the above code works when connecting to a node.js server, so the issue appears to be with the netty-socketio server.
Here is how the netty server is initialized:
Configuration config = new Configuration();
config.setHostname("localhost");
config.setPort(3031);
server = new SocketIOServer(config);
server.addNamespace('/nsp')
I finally figured it out. I had to revert the node.js client version to 1.7.4 (https://www.npmjs.com/package/socket.io-client/v/1.7.4) to get it to work. Not sure why I was forced to use such an old client to be able to use namespaces.
I've created a application with Vue and Node js but I get a trouble "CORS" when I try to connect to a public websocket from "http://localhost".
Project structure
Error log
I believe the cause of this problem is a trying to connect via http to a https server.
Any idea to solve this problem in localhost ?
Try installing this node package named cors-server that will start a web server on a given port that will proxy any request received and add CORS headers to it.
To start the server simply call it from the command line and supply a port number
cors-server <port>
After that, any requests sent to http://localhost:[port] will have Access-Control-Allow-Origin: * on the response.
e.g:
POST http://localhost:3005/http://www.google.com
Hope this helps!.
The real problem in this case, is to try to connect to other domain from the client side and the server do not allow "Access-Control-Allow-Origin".
The best solution for this question is follow the arquiteture of project bellow:
https://github.com/Tucsky/SignificantTrades
In resume, implement conection websocket in server side and expose a local websocket in the client side.
In my case, Node and Vue js.
I am using sockets.io with nodejs server to send/receive events between client and server.It works well on local pc but the issue comes when i have to connect a remote client to it and i dont need to use frontend template file or html. In that case, how can i define io() object i.e. a socket connection because without it i cannot access my nodeserver. Currently i have created a js file on remote client and it looks like this:
`var socket=io.connect('http://a.b.c.d:3000');
var name="alice";
socket.emit('ping',(name)=>{
socket.on('pong', reply);
console.log(reply);
});`
Web Sockets work over the HTTP protocol, so you need to run a server for it.
I am implementing web server using express module, the web server communicates with the backend server to get the data and send to UI.
Now if due to some reason the backend server does not send any data, then TCP connection does not get closed. How I can implement connection to backend server close after some timeout period?
I am not using socket.io module.
Regards,
-M-
If you are using Socket you can close the server connection using:
socket.on('timeout', function () {
socket.close();
});
You can also:
socket.setTimeout()
socket.setKeepAlive()
this is my first node.js and socket.io application , i didn't use express ,I want to deploy the application on heroku do i need to use it ? i mean i just did npm install socket.io on localhost and in my server file i.e game.js i have io = require("socket.io") and socket = io.listen(Number(process.env.PORT)) only and in one of the files where from where i am sending the message i have socket = io.connect();
so please tell me if i need to use express and how show i modify my existing application ?
I have given the link to the source of application
( https://github.com/bitgeeky/herokutest )
Although the Application works fine on localhost by changing the port no , to some port no like (8000) but Heroku error log on doing "heroku open" is http://pastebin.com/MtB0z5vQ
I noticed that you haven't created a http server. I am assuming that you are creating a web application, since you are deploying to heroku. For that, you need to create a http server in nodejs.
Go through socket.io https://github.com/LearnBoost/socket.io
Also http://socket.io/#how-to-use
This should get you started
Note: You do not need express. But it will make your work easier in many ways. Depends on the type of application that you want to create.