Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:12:39+00:00 2026-06-15T10:12:39+00:00

I have a websockets program in play 2.1, which works just fine and the

  • 0

I have a websockets program in play 2.1, which works just fine and the template looks like this:

// Contents of the view.scala.html file
@(userName: String)(implicit request: RequestHeader)

@main("text") {
  <script type="text/javascript" charset="utf-8">
  $(function() {
    var WS = window['MozWebSocket'] ? MozWebSocket : WebSocket;
    alert("before")
    var socket = new WS("@routes.Application.view(userName).webSocketURL()");
    alert("after")
    socket.onmessage = function(event) {
      alert(event.data);
    };
  });
  </script>
}

The issue is that as soon as I move my javascript into the assets.javascripts folder and change the view.scala.html file into the following it stops working.

// Contents of the view.scala.html file
@(userName: String)(implicit request: RequestHeader)

@main("text") {
  <script type="text/javascript" charset="utf-8"
          src="@routes.Assets.at("javascripts/viewer.min.js")"></script>
}

Play finds the file, executes the javascript, I can see the popup triggered by the alert("before") line of code, but after that… nothing.

This is the google chrome error I get in the console:

Wrong url scheme for WebSocket
http://localhost:9000/@routes.Application.view(userName).webSocketURL()

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:12:39+00:00Added an answer on June 15, 2026 at 10:12 am

    A WebSocket needs ws:// or wss:// (for SSL) instead of http://.

    However, the problem in your code is that the statement @routes.Application.view(userName).webSocketURL() apparently isn’t replaced with some useful value but kept as-is. This is because your framework seems to consider assets completely static and thus ignores anything in there that would be a placeholder/variable in a normal template.

    One possible solution for your problem would be keeping the URL in your template, e.g. by adding data-ws="@....." to your <body> tag and then use JavaScript to extract that attribute:

    var socket = new WebSocket(document.body.getAttribute('data-ws'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I have a gen_server speaking to several hardware sensors. This setup works fine. Now
I'm using socket.io with Node.js. Everything works fine with websockets, but I have to
I have a JavaScript Websockets implementation where I would like to use a singleton
have written this little class, which generates a UUID every time an object of
Have deployed numerous report parts which reference the same view however one of them
I am using node.js socket.io-client and socket.io . I have a javascript program which
I have a webpage for which I grab the html, send it through websockets
WebSockets? I just recently ran across websockets and have heard some good things about
I have an application whose primary function works in real time, through websockets or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.