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 6652311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:07:17+00:00 2026-05-26T01:07:17+00:00

I am trying to get started with WebSockets, and trying to write a simple

  • 0

I am trying to get started with WebSockets, and trying to write a simple application to send messages back and forth via a websoket.

However, it looks like the socket that I am trying to create never gets connected. Why can that be?

Below is the code of my WebSockets class. When .onConnect() is called, it logs:

I am socket, I was connected. Am i connected? – false

Update: in JavaScript, where I create the socket in question, the readyState is 1, which means “socket open, communication is possble”.

import a.b.Misc; //writes logs.

import com.sun.grizzly.websockets.BaseServerWebSocket;
import com.sun.grizzly.websockets.DataFrame;
import com.sun.grizzly.websockets.WebSocketListener;

public class ChatWebSocket_v2 extends BaseServerWebSocket {
    private String user;
    public ChatWebSocket_v2(WebSocketListener... listeners) {
        super(listeners);
    }
    public String getUser() {
        if (user == null) {
            Misc.print("User is null in ChatWebSocket");
            throw new NullPointerException("+=The user is null in chat web socket");
        }
        return user;
    }
    public void setUser(String user) {
        Misc.print("Just set user: " + user);
        this.user = user;
    }
    @Override
    public void onMessage(String message) {
        Misc.print(message +"\n");
    }
    @Override
    public void onMessage(byte[] message) {
        Misc.print(new String(message) +" << Bytes\n");
    }
    @Override 
    public void onConnect() {
        Misc.print("I am socket, i was connected. Am i connected? - " + this.isConnected());
    }
    @Override 
    public void onClose(DataFrame df) {
        Misc.print("I am socket, i was closed");
    }
}
  • 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-05-26T01:07:18+00:00Added an answer on May 26, 2026 at 1:07 am

    If you’re just trying to make a connection somewhere, you might want to try this instead. There is a live working demo and you can download the javascript code and play with it yourself. Note that the javascript code only works if you have it installed on a server (due to browser security because it’s ‘fancy’.) There is also a step by step browser-based client tutorial in the works that I will post as soon as it’s ready. Most proxy servers haven’t been upgraded to handle websockets so they will screw up connection request and most people won’t be able to connect to websocket servers from work. Firefox 7 (release) or Google Chrome 14 or later support the latest version of the websocket protocol that the demo server runs.

    If you want to try to get the grizzly demo working, you might have some debugging to do and maybe I’ll help with that. Note that in comments below the article, other people said they couldn’t get it working either and I haven’t found any follow up. At this point it seems no better than the echo app above even if we do get it running and is possibly overly complicated and underly documented if you’re just trying to get started. But if you want to try to get it running, you should ‘git’ the latest version of the code here, which was at least committed recently and may be fixed.

    Then make sure that app.url in the application javascript file is set to your installation directory. His is hard-coded as:

    url: 'ws://localhost:8080/grizzly-websockets-chat/chat',
    

    If you’re using Firefox 7, the javascript needs to be modified to use the Moz prefix, for example:

      if (typeof MozWebSocket != "undefined") { // window.MozWebSocket or "MozWebSocket" in window
        ok
      } else if (window.WebSocket) {  // he uses  if ("WebSocket" in window)
        ok
      } else {
        do your print "browser doesn't support websockets"
      }
      .... then if the browser supports websockets
      websocket = new WebSocket(app.url); or
      websocket = new MozWebSocket(app.url); 
      // depending on which it is.
    

    The HLL websocket server demo code has this all sorted out.

    (another) UPDATE: As I work through grizzly myself, I found on the Quick Start in the glassfish admin console, there’s a hello sample that’s pretty easy to set up and run. You’ll find instructions there. The sample directory also contains a war file named: websocket-mozilla; so I guess its supposed to use websockets. Someone who’s familiar with jsp should review the source code. All I can see is that it’s using an http session. No mention of a websocket at all. It’s a lot like the hello sample.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get started with a simple audio application under .NET 3.5 (preferably
Trying to get started with subsonic but have a simple question about stored procedures
I'm trying to get started with the jQuery plugin, jqGrid, however it's giving me
I'm just trying to get started with Java EE and related concepts. However, I'm
Trying to get started with Amazon SNS. API is very simple REST. I seem
I am trying to get started developing using the .NET Micro Framework but appear
I'm trying to get started with USSD . I'm familiar with other forms of
I'm trying to get started with unit testing in Python and I was wondering
I am trying to get started writing scalable, telecom-grade applications with Asterisk and Ruby.
I am trying to get started with scons . I have Python 3.0.1 and

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.