Im making a private network Chat.
I need to have my server and clients not connected to the internet. but the socket io grabs the javascript from the internet when it loads the page client side.
Whats the best way to fix this? can i push the socket io javascript to the client from the server?
AKA go:
http://SERVER/socket.io-1.2.0.js
instead of:
https://cdn.socket.io/socket.io-1.2.0.js
socket.io will automatically expose the client library through the HTTP/Express server it is attached to, as /socket.io/socket.io.js (so the full URL in your case would be http://SERVER/socket.io/socket.io.js)
Related
I have node.js server, and I need to create dynamically updated web page with updating data. So, I thought that sockets are way to go.
But there's one problem. I need to send data from the server to client(to browser).
From my research, it is not really possible to create socket server with the client side JS. It is easy to do it the other way, but to send data only from server to client?
What would be best and easiest way to do that?
You create a webSocket or socket.io connection from your client to your server and your server is the webSocket or socket.io server. Once that connection is established, you can then freely send data either way across the connection, from client to server or from server to client.
This type of architecture is ideal for sending data from your server to a web page to dynamically update the web page as new data arrives.
webSocket is the base transport. socket.io is a layer on top of webSocket that adds a bunch of useful features such as auto-reconnect and structured messages. You can use either from a browser. webSocket support is built-in to the browser. If you want to use the additional features of socket.io, then you include the socket.io client library in your web page.
Here's a listing of some of the additional features socket.io offers over a plain webSocket: Moving from socket.io to raw websockets?.
I am not sure I have fully understood your question.
But, if I got it correctly, in order to have a "socket connection" you need to have two sides - a server and a client.
Use socket.io lib with a lightweight node.js server.
You can take a look at their docs + examples - will be very straight-forward.
If you still having trouble, write.
I have an app where I am trying to connect to a C++ server which opens up a socket.
// Client side
var ws = new WebSocket('ws://<<IP:PORT>>');
In the server side, it is opening up a socket using
int sockfd = socket(domain, type, protocol)
(ref: https://www.geeksforgeeks.org/socket-programming-cc/)
Not aware of the c++ server implementation.
I was told that the server would start a WebSocket server to which my HTML app can connect.
But, the connection is not happening. I feel that the WebSocket on the client side is not same as socket on the server side and hence the connection is not establishing.
Please, someone, suggest what is wrong and how to make it right.
P.S. Please don't mind if it is a dumb question.
Since the server guys are not ready to change their implementation of the plain socket, as a workaround I created a C++ client which connects to the server using the plain socket. Then I am creating a WebSocket Server using NodeJs which executes the C++ client as a child process to get the data. So, my WebSocket client is now able to get the data from the main server through the NodeJs WebSocket interface server.
Cons:
A dependency of the C++ client.
Latency (since network speed is not a factor now, it works).
Im looking form something to make socket connection between client, without pass through the server. Is there any node package to do this?. Server only send the other client socket, and the clients recieve and send data to each other..
Or, how can we make the implamantation. We need to make a server in client side, but we dont have node installed in the client..
The closest thing that currently exists in some form is not currently part of socket.io. It is called WebRTC and is implemented in Chrome currently. It allows the browser to connect with other browsers.
http://www.webrtc.org
The question is what kind of application is your client? If you are talking about ordinary webbrowsers you need to think about writing pluings (tough case).
If you are talking about clients you have more control then you should look at technique Puching the hole exploited by Skype or P2P apps.
http://it.slashdot.org/story/06/12/15/191205/how-skype-punches-holes-in-firewalls
In general the server is used for TCP sockets orchestration the acutall comunication go directly.
So I've been looking at socket.IO and I've stumbled upon some problems. I'm trying to create a WebSocket based chat but It seems that I can't find how I would go about creating a chat where the client is hosted on a different server than the socket.io server. I have a PHP based client that needs to connect to the server but I basically want to know how I can connect to a external socket.IO websocket server.
I would follow this really great tutorial to start with.
At this line of code:
033 socket = io.connect("http://localhost:3000");
Replace with your server address.
I'm really new to Node.js and have been wondering something. I'm trying to build a simple chat room application as a way of teaching myself how this all works.
The way I see it working is that I have a Node http server which serves the pages of my site (homepage, login, chat screen etc) and then I have a WS server which accepts short messages to relay to all connected users.
The thing is I can't work out if this is the correct way to approach this. Is it possible to authenticate users on the Node server and know that they have been authenticated on the WS server? Can they share some kind of session?
Any help is appeciated!
You don't mention what you're using to implement a WebSocket server, so I'll assume you're using socket.io. (If you're not, you should.)
You can use the socket.io handshake process to access the HTTP session state.
If you're using Express (once again, highly recommended), it's easy to tie the two together.