Get IP of Websocket on known port - javascript

I have built a websocket in C++ (using boost::beast).
It is going to serve a website (client) with a JSON string if requested.
When designing my setup I made a disastrous mistake: I forgot that the client web browser (that is running on a separate device from the server) will not know the IP address of the server. It will know the port that the server is listening on.
I should specify: Both (server and client) are running in a local network.
So I have two clumsy ideas to resolve this. I would be very happy to hear your input – I am sure there will be a more elegant way to fix my problem.
Send some kind of broadcast message “Very specific string” into the network. My server will know that it is been looked for and will respond with its IP, so that the connection can be established.
This post seems to indicate that this approach will not be possible.
Have the user input the (known) IP address of the device that is running the server. I would really like to avoid this last resort solution.
Unfortunately, I cannot run node.js on the device that is hosting the websocket server.

I might not be understanding the problem. Why aren't you capable of knowing the IP of the server? Is it due because it changes? Is it because it's a server you don't know?
Maybe the solution is not about finding the IP rather than knowing beforehand the server IP address.
I could recommend checking out this post to find out the IP address in your local network. If you at least know the servername of the server that could be helpful.

#E.Soria
Thank you for your answer! I was not precise enough.
The problem was, that the server is running on a device that is going to be part of our customer’s network. The customer will define the IP address for the device, which means that I need some way of getting the address of the server.
But I might have found another solution (as you might already be able to tell I am very new to networking, so this just may be wrong): I will host the website on the same device that is hosting the server and supplying the data. Then I can just establish a websocket connection through javascript like this: let socket = new WebSocket(ws://127.0.0.1:8080); and have the website read data from the server. This seems to be very straightforward and I am a little embarrassed that I did not think of this before.
I just had not really understood how the internet works :) As long as the user who wants to see the website knows where it is hosted, he/she can just connect to the website and will see anything that I put on there.

Related

Websocket certificate for local network

I am having trouble with certificate when using websocket (WSS://).
What is working
For now, I've been using websocket with WEB_SOCKET_FORCE_FLASH = true and I had no issues with connecting to my websocket server.
What is not working
I am trying to turn that option off, to stop using flash plugin for connecting. Problem occurs when i try to connect my websocket client to server. WebSocket opening handshake was canceled message appears.
I can disable this message, by going to https://127.0.0.1:9999. My browser will show that "This Connection is Untrusted", and if I add an exception here, my websocket connection will start working without any problem from now on. But i CAN'T make every end user to do that, right?
Google groups with this idea
What I need?
Is there any way, to buy, or create some self-signed certificate, which I can use? The problem is also that, it doesn't have to be localhost/127.0.0.1 but also any other IP in local network. (like 192.168.0.100 etc). End user can change that IP whenever he likes to. He just needs to point on the PC where my desktop app/websocket server is running.
What have I tried?
I sure tried to find my answer in google, browsing tons of forums, sites, and even few questions and all answers here on stack overflow.
I also tried not using certificate at all, but my page is on https:// so connection using ws:// is impossible.
Code
I know, code is usually obligatory, but I actually got my websocket client/server working, but the issue is certificate, so i hope you can forgive me lack of code.
missing info?
Do i need to provide any more information? I am willing to make multiple edits if needed.
While the current certificate system is kind of broken it is fortunately not broken enough to allow what you want. What you expect to get based on your description is a certificate for an IP addresses (bad idea anyway) which you don't even own fully (you cannot claim to be the owner of 127.0.0.1 or similar addresses) which then will be accepted by every browser without the need to add a manual exception by the user.

WebRTC ~ Possible to connect when knowing IP and PORT without using Intermediate Servers

I know there is lot's of documentation about WebRTC out there so I am sorry if I missed it:
My question is the following:
Is it possible to connect from client to client without using an intermediate server. ( Including an intermediate server to set up the connection )
Take as example two clients that know each other IP addresses and the ports they are using for RTC. Both did they already downloaded the webpage. Is it possible for them to connect without an intermediate signal server?
I hope you would point me to a good source of how this is possible! Or why not!
Thanks
It is not as easy as that to set up the connection. There is more information that needs to be provided than ip and port. There are 'offer', 'answer' and 'candidates' that are sent between the peers.
These are readable text and the could very well be typed in by the user but since they are quite large, it is more easy to provide them via the server in the middle.
You could mail them and type them in at the remote peer...

Multicast send from JavaScript?

I have a situation where I need to get some information from an application written in JavaScript, to another computer over the network, but neither system knows the ip address of the other. Multicast really seems like the right answer to me. This communication would require small and frequent update messages, perfect for a light multicast stream.
The problem is that I don't think JavaScript can send UDP messages and I don't think JavaScript can trigger external applications to send the messages on its behalf.
How can I solve this problem?

How to trace friend's ip address while chating

How do I trace my friends IP address while chating (in facebook,gmail ) ?
Can we do this in jquery ?
Please let me know your pointers.
Thanks,
-Pravin
No you cannot because your javascript chat application does not communicate directly with your friend's browser. It all goes through the server side chat application (gmail, fb... etc) so you are only communicating with that IP which communicates with all the rest.
Of course the server side chat application could be somehow revealing the chat participants IP addresses but this is highly unlikely in any web based chat application that it's used in production right now.
The easiest way to find out the IP of a chat participant is to make him/her click on link for which you'll be monitoring http traffic. I hope it's for a good reason :)
I do not think it is possible since you both connected to the chatting server and all information go through them and there are no direct link between you and your friend.
You can't from a browser. The chat protocol is implemented on the server side, and your browser doesn't know the IP address of your correspondant.
As others have said, you can't do this directly. The only way around it then is to give your friend a link to a script on your server that then alerts you of the IP address.
Basically, such a script would check the remote address, and then log it somewhere or e-mail it to you. That script might then return an image or redirect somewhere so that the person you sent the link to isn't so aware of what happened.
You should also know that the remote address isn't necessarily the IP of your friend. It could be a proxy server, or something else getting in the way. It's more common than you might think.

Javascript TCP connection to server

I have created server daemon, that produces some data, like messages and so. But, what im interested in - client monitoring. For example i have web page, and i need to establish persistent Tcp connection to server and show all incoming data into textbox. I know it can be done with flash, but im searching for JS implementation.
Is it possible and what`s the best practices ?
What you're asking for is known as Comet. Plenty of server software and client libraries exist - see the linked Wikipedia page.
WebSockets is designed to solve this problem.

Categories

Resources