LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-22-2017, 08:59 PM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 921

Rep: Reputation: 61
JS Websocket from scratch - What error?


So I have in my socket.html file

Code:
<html>
  <head>
    <script type="text/javascript">
      //create a new WebSocket object.
      websocket = new WebSocket("ws://d30:9000/socket.php");
      websocket.onopen = function(evt) { console.log('Socket Opened'); }; //on open event
      websocket.onclose = function(evt) { console.log('Socket Closed'); }; //on close event
      websocket.onmessage = function(evt) { console.log('Message Recieved'); }; //on message event
      websocket.onerror = function(evt) { console.log(evt); }; //on error event 
      //websocket.send(message); //send method
      websocket.close(); //close method
    </script>
  </head>
<body>
  Socket Test
</body>
  
</html>
And in my js console on Firefox I get.

Code:
<unavailable> 
Socket Closed
How do I actually see what the error is?
 
Old 05-24-2017, 01:20 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,258
Blog Entries: 24

Rep: Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193Reputation: 4193
As no one else has stepped up, I'll take an educated guess (having never used the websocket protocol).

I think that what you see and have posted is the complete "error".

Code:
<unavailable> 
Socket Closed
The target or socket is unavailable, so you are receiving the onclose event message. There is no additional error to report in the client context.

To work, the socket must have been defined in the headers received from the server in response to the initial request, if I have understood the protocol from an admittedly quick reading.

This:

Code:
ws://d30:9000/socket.php
...doesn't have meaning without any server context.

From what I have quickly surmized about websockets I think we need to know what is in the server response headers and the server.php code. You should check any errors on the server generated by that code. You cannot simply open a websocket to your server from javascript.

This explanation
appears to describe the required handshake, server side php requirements, response headers and session communications.

Hope that helps.

Last edited by astrogeek; 05-24-2017 at 01:22 AM. Reason: Broken link
 
1 members found this post helpful.
Old 05-24-2017, 02:33 AM   #3
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 921

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by astrogeek View Post
As no one else has stepped up, I'll take an educated guess (having never used the websocket protocol).

I think that what you see and have posted is the complete "error".

Code:
<unavailable> 
Socket Closed
The target or socket is unavailable, so you are receiving the onclose event message. There is no additional error to report in the client context.

To work, the socket must have been defined in the headers received from the server in response to the initial request, if I have understood the protocol from an admittedly quick reading.

This:

Code:
ws://d30:9000/socket.php
...doesn't have meaning without any server context.

From what I have quickly surmized about websockets I think we need to know what is in the server response headers and the server.php code. You should check any errors on the server generated by that code. You cannot simply open a websocket to your server from javascript.

This explanation
appears to describe the required handshake, server side php requirements, response headers and session communications.

Hope that helps.
I appreciate the help. I've abandoned using websockets for now. They are a bit over my head and it's difficult for me to find documentation on how to setup the system that I can actually understand.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Webserver to websocket server connection issue rtlm1 Linux - Networking 1 05-11-2015 02:30 PM
WebSocket over SSH tunnel - is it possible? Vlad.BG Linux - Networking 3 01-18-2015 07:42 AM
LXer: How to configure Varnish for WebSocket traffic LXer Syndicated Linux News 0 04-04-2014 07:41 PM
Linux from Scratch -> Glibc-2.5.1 error jramirez07 Linux From Scratch 2 02-08-2009 04:22 PM
ali aladdin v agp stinks :scratch: :scratch: :scratch: Mr Marmmalade Linux - Hardware 1 07-08-2003 05:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration