1

What I want to do

Make a simple socket connection to a server on the browser. I want to not send any header information with the socket connection.

The Problem

It looks like I am unable to make a socket connection with javascript that does not send header data (Is there a way to do a tcp connection to an IP with javascript?).

I thought maybe I could make a connection with a chrome extension, however it looks like the socket API is only available for chrome apps (Google Chrome Socket API in extensions).

I am thinking that I might need to make a native application that will make socket connections through requests made by the browser using Native Messaging.

Is there anyway I can achieve this or am I out of luck?

Community
  • 1
  • 1
Tony
  • 2,890
  • 1
  • 24
  • 35

3 Answers3

1

Raw socket connections through the browser are wrapped up in security concerns. Users can be easily manipulated to allow things to run that shouldn't.

TCP and UDP Socket API W3C Editor's Draft 20 January 2016

is located here.

http://raw-sockets.sysapps.org/

Mozilla's API information here: https://developer.mozilla.org/en-US/docs/Archive/B2G_OS/API/TCPSocket "This API is available on Firefox OS for privileged or certified applications only."

If you work with raw TCP connections. I would suggest

(1) downloading PHP onto the local computer. PHP has a developer web host build in so you can run whatever application you want on PHP using the browser as your GUI.

(2) download node.js.

Wayne
  • 4,760
  • 1
  • 24
  • 24
  • I don't think running php locally is an option for us, and I don't think the server we are making a request to is running node.js. Does it need to be running node.js for us to make a connection? – Tony Mar 21 '17 at 20:31
  • Node.js can run on either or both machines. It can make or accept requests and is javascript based. Node.js raw socket API is documented here: https://www.npmjs.com/package/raw-socket – Wayne Mar 22 '17 at 05:21
  • from my understanding Node.js will make a socket connection from our webserver. We need to make the connection between the browser and a device on the same network. – Tony Mar 22 '17 at 16:16
  • Node can do both ... client and server example - https://gist.github.com/tedmiston/5935757 – Wayne Mar 23 '17 at 03:57
  • adobe air can do both as well and has a gui interface for the user. ... here is a example of a client and server for adobe air. Most programmable systems can do both. The browser is restricted because or for security reasons. Since people know or should know other programs can talk on the network there is no reason for restrictions on anything but the browser. ... may not make much sense but it is ok for other programs to access user data and send it across the network, **but not the browser.** – Wayne Mar 23 '17 at 04:14
0

You are not out of luck you just need to achieve it with the understanding that you are working outside the box for normal browser based scripting created from security concerns, and that means the user/client needs to install something manually.

If you must use chrome browser on the client side, you will need to make an -extension- correction webapp. You can as a developer make one that you can use on your own computers.

https://developer.chrome.com/extensions/getstarted https://developer.chrome.com/apps/first_app

Load the extension#

Extensions that you download from the Chrome Web Store are packaged up as .crx files, which is great for distribution, but not so great for development. Recognizing this, Chrome gives you a quick way of loading up your working directory for testing. Let's do that now.

Visit chrome://extensions in your browser (or open up the Chrome menu by clicking the icon to the far right of the Omnibox: The menu's icon is three horizontal bars. and select Extensions under the Tools menu to get to the same place).

Ensure that the Developer mode checkbox in the top right-hand corner is checked.

Click Load unpacked extension… to pop up a file-selection dialog.

Navigate to the directory in which your extension files live, and select it.

Alternatively, you can drag and drop the directory where your extension files live onto chrome://extensions in your browser to load it.

If the extension is valid, it'll be loaded up and active right away! If it's invalid, an error message will be displayed at the top of the page. Correct the error, and try again.

This insures that non developers don't load an extension which does not comply with the normal security concerns.

Communicating between with the script on the web page to the extension.

  • Can be done with message passing ... https://developer.chrome.com/extensions/messaging
  • The extension can add content directly to the web page which is available to the script on the web page. If for example the extension replaced the web cam image with a static image when the webcam script reads what it believes is the webcam it gets the static image instead, which explains why I look like an alien from space on the webcam. Although I did not create an extension to do that, I merely modified an existing extension to replace the function that gets the webcam image with a function to get a static image.
Community
  • 1
  • 1
Wayne
  • 4,760
  • 1
  • 24
  • 24
  • 1
    I have tried making a socket connection from a chrome extension, however it seems google's Socket API [is only available for chrome apps](http://stackoverflow.com/questions/13921970/google-chrome-socket-api-in-extensions?noredirect=1&lq=1). I am hesitant to make a chrome app to achieve this because google is [ending support for chrome apps](http://www.theverge.com/2016/8/19/12555052/google-shutting-down-chrome-apps). – Tony Mar 23 '17 at 15:27
  • Security concerns are going to be considered first and as most important within the browser environment. W3C raw sockets may never actually get implemented / Mozilla's API may get discontinued. JSON is here to stay. Hence the quilfier words like, must. I don't believe that Google does not want to not have something in the windows desktop development field, but that is a opinion. Mozilla is holding onto XUL, adobe onto air, Perl has GUIs, even PHP has GUIs for windows. Appjs is a GUI for node.js. Would seem Chrome would need to have something ... just separate from client's anonymous browser – Wayne Mar 25 '17 at 11:54
  • 1
    thanks for your help with this. I was able to solve the issue by creating a native application that talks to the browser through a socket connection on the localhost. The application was able to then parse and forward a proper request. – Tony Mar 25 '17 at 16:11
  • that should work best as those worried about browser security would not break the system in the future. – Wayne Mar 25 '17 at 22:01
-2

You can use SignalR, it is javascript library (JQuery Plugin) and it enables you to open web sockets from the browser to a server. Please check the following links:

https://blog.3d-logic.com/2015/03/29/signalr-on-the-wire-an-informal-description-of-the-signalr-protocol/

http://blog.teamtreehouse.com/an-introduction-to-websockets

https://github.com/SignalR/SignalR