Websocket session has ended

Delving into the world of webSockets, Angular, and Play framework has been a rewarding journey so far. I've been utilizing https://github.com/AngularClass/angular-websocket for seamless integration with Angular. The connection setup like this:

var dataStream = $websocket('wss://echo.websocket.org/');

runs smoothly. However, attempting to connect to:

var dataStream = $websocket('wss://localhost:9000/socket');

leads to the following error:

WebSocket connection to 'wss://localhost:9000/socket' failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED

The logs from Play/Netty only show:

 play.core.server.netty.PlayDefaultUpstreamHandler - Exception caught in Netty
java.lang.IllegalArgumentException: empty text 

This is the code snippet used on the backend:

def socket = WebSocket.acceptWithActor[String, String] { request => out =>
    MyWebSocketActor.props(out)
  }
object MyWebSocketActor {
  def props(out: ActorRef) = Props(new MyWebSocketActor(out))
}
class MyWebSocketActor(out: ActorRef) extends Actor {
  def receive = {
    case msg: String =>
      out ! ("I received your message: " + msg)
  }
}

(taken from: )

You can view my code here: https://github.com/dataplayground/playground/blob/master/public/javascripts/main.js

Answer №1

As I mentioned previously:

  1. Have you attempted using the regular ws protocol instead of the secure one (wss)? It should be like this:

    $websocket('ws://localhost:9000/socket')

  2. You have specified an actor that handles [String, String], but in your Angular part, you are working with JSON. Both should align, so consider using:

    WebSocket.acceptWithActor[JsValue, JsValue]

I am uncertain if you are returning valid JSON data and handling it correctly on the Angular side.

If you use the backslash \ method (), you will obtain a JsValue, but this does not necessarily denote valid JSON. For instance, if you have {"foo": "test"} and search for for, you will get "test," which is not valid JSON.

To quickly address this, try either changing the Websocket Actor to be of type [JsValue, String] OR construct a new JsValue within your Actor:

class MyWebSocketActor(out: ActorRef) extends Actor {
  def receive = {
    case msg: JsValue =>
      Logger.debug("actor something  " + out)
      Logger.debug("message  " + Json.prettyPrint(msg))

      val json: JsValue = Json.parse("""
      {
          "fooReply" : "Something"
      }
      """)
      out ! json
  }
}

Edit:

Is this related to ng-websocket where you need to access the data property instead of directly using message?

dataStream.onMessage(function (message) {
    collection.push(JSON.parse(message.data));
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

UI-router causing issues with recognizing query parameters

I am trying to route to a state by using the complete URL with query parameters and then perform an action in the controller based on those query parameters. So far, everything works fine when I use a simple routing URL with variables like: "/load/:portNa ...

Activate the timepicker in Bootstrap when the user clicks on the input field

Struggling to implement a timepicker feature? Look no further than this resource. After adding the necessary js and css to your project, you may encounter issues with the popup not appearing when clicked. The code provided offers a TextBox control with s ...

When utilizing the POST method, the information is submitted to the server without being displayed

Why is my POST method not displaying on the webpage when the GET method does, even though I have not created a method for it in my global.js file? Does the GET method automatically come with POST? I specifically want my POST method to be displayed and not ...

Issues with finding your way

Whenever I am in the History.js file and click on a product list item to navigate to another page for more details and contact the seller, the issue arises. When I click on an item in History.js, nothing happens on that page. However, when I switch to Home ...

Temporarily suspend an application when a user initiates a new tab in AngularJS

I've successfully created a music application using AngularJS. Users can play, pause, skip to the previous or next song on their tab. However, I'm looking to enhance the functionality even further. My goal is to have the music automa ...

fetch and modify data simultaneously in firebase

Is there a way to retrieve a value from a Firebase document and immediately update it? I am familiar with methods for updating documents and retrieving their values separately, but how can I accomplish both in one go? update firebase.firestore().collecti ...

Is there a way to use SCTP with Socket.io and Node.js?

I have a new project in the works, creating a web application that will utilize web sockets to provide real-time updates for users. The plan is to seamlessly transmit changes from the back-end engine. My challenge lies in Node.js not supporting SCTP sock ...

What could be causing only the initial DropDown to be filled with content when dynamically creating DropDowns with Jquery?

I'm currently working on developing a dynamic DataEntry grid or table that allows users to add new rows with different input fields like TextBoxes, DropDowns, and a Calendar Control upon clicking a button. The goal is to handle this functionality on t ...

Tips for gradually increasing numerical values line by line

Plunker. After implementing the Plunker provided above, I noticed that the rowId is increasing with alphabets, as shown below: The component in the Plunker contains buttons labeled with +, ++, and -. When you press the + button, the rowId starts from the ...

Seeking assistance to prevent data duplication when transferring information from list1 to list2 in React.js

As I work on developing two lists in React.js, I encountered an issue with avoiding repetitions when transferring items from list-1 to list-2. I need assistance creating a function that prevents duplicate items in list-2 while also ensuring that the items ...

Connecting Node.js with Express.js allows you to access the session data from the "upgrade" event

I'm currently facing a challenge with accessing the session object from an 'upgrade' event triggered by my Node.js server using the Express.js framework. Although I have successfully set up Session support and can retrieve it from the standa ...

The functionality of TabIndex is not compatible with input elements when used within RadWindow

I am utilizing Telerik Rad Window to display certain content. Within the RadWindow, I am dynamically inserting 4 input elements using a jQuery script. $.each(inputs, function(i, input) { $('#table').append('<tr id="' + input.id ...

Obtain the Zero-width non-joiner character (‌) using the innerHTML attribute

I am attempting to retrieve a &zwnj; using the innerHTML method The desired output should be This section contains a zero-width‌&zwnj;non-joiner, a non-breaking&nbsp;space &amp; an ampersand However, the current output is: This part c ...

"Discover how simple tips can enhance your website's user experience by enabling

I am attempting to retrieve content from the database using simpletip. Here is my code: <script type="text/javascript"> $(document).ready(function(){ $('a.regularsList').simpletip({ onBeforeShow: function(){ ...

Navigate the user to various pages in a Node.js application based on login status

Looking for guidance on a login system within my application? I need to redirect users based on their roles. Below is the code for the login controller, along with node.js snippets and the login HTML page. Any help would be appreciated. Login.html - < ...

Show the value in a field without permanently storing it in the model

Imagine I have this input: <input ng-model="myinput" /> I need it to show a default value of Hello when the page loads, but without affecting myinput. Using a placeholder won't work because I want users to be able to modify the default value ...

Converting date formats using AngularJS

After clicking the search button and the radio button, I am converting the date format. Everything works fine when I search by date, but I encounter a problem when I click the radio button. HTML Code <form action="{{URL::current()}}" ng-submit="submit ...

Unraveling the Mysteries of AngularJS in a Tutorial Snippet

After reading through the enlightening theory snippets in Step 3 of AngularJS Tutorial, one particular passage piqued my curiosity: The scope, which connects our controller and template to create a dynamic view, is not isolated within its own bounda ...

What causes button events to cease after the 3rd click?

Check out this website: For instance, locate Number 133 and click on it. You will notice a new vibrant button on the right side. Click on it and wait for 2 seconds. It will change. Click again and wait another 2 seconds. It will change once more. Excitin ...

Is there a way to connect JSON data with an HTML table using AngularJS?

Can you help me figure out how to display this JSON data in an HTML table using Angular.js? [{"keycolumn1":1,"originkey1":1,"datafield1":1}, {"keycolumn1":2,"originkey1":2,"datafield1":2}, {"keycolumn1":3,"originkey1":3,"datafield1":3}, {"keycolumn1":4, ...