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

  • SEARCH
  • Home
  • 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 8153015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:52:55+00:00 2026-06-06T15:52:55+00:00

I’m trying to start a very simple jWebSocket Client on Android and connect it

  • 0

I’m trying to start a very simple jWebSocket Client on Android and connect it to my local server. I’m using the JWC class from the demo together with jWebSocket 1.0 beta 8 and Android 4.0.3, my code looks like this:

import org.jwebsocket.api.WebSocketClientEvent;
import org.jwebsocket.api.WebSocketClientTokenListener;
import org.jwebsocket.api.WebSocketPacket;
import org.jwebsocket.client.token.BaseTokenClient;
import org.jwebsocket.kit.WebSocketException;
import org.jwebsocket.token.Token;

import android.app.Activity;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import cased.smids.communication.JWC;

public class TasksActivity extends Activity implements WebSocketClientTokenListener {
   Spinner spinner;
   Button btn_Start;

    /** Called when the activity is first created. */
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main);

        JWC.init();

        spinner = (Spinner)findViewById(R.id.sp_Task);
        btn_Start = (Button)findViewById(R.id.btn_Start);

        ArrayAdapter<CharSequence> adapter = 
                ArrayAdapter.createFromResource(
                        this,
                        R.array.Tasks,
                        android.R.layout.simple_spinner_item
                );
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);

        btn_Start.setOnClickListener(new View.OnClickListener() {
            public void onClick(View src) {
                switch (src.getId()) {
                    case R.id.btn_Start:
                        if (spinner.getSelectedItem().toString().equals("Connect")) {
                            try {
                                System.out.println("connecting manually...");
                                JWC.open();
                            } catch (WebSocketException e) {
                                e.printStackTrace();
                            }
                        }
                    default:
                        break;
                }
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        System.out.println("* opening... ");
        try {
            JWC.addListener(this);
            JWC.open();
        } catch (WebSocketException ex) {
            System.out.println("* exception: " + ex.getMessage());
        }
    }

    @Override
    protected void onPause() {
        System.out.println("* closing... ");
        try {
            JWC.close();
            JWC.removeListener(this);
        } catch (WebSocketException ex) {
            System.out.println("* exception: " + ex.getMessage());
        }
        super.onPause();
    }

    public void processClosed(WebSocketClientEvent arg0) {
        System.out.println("closed");
    }

    public void processOpened(WebSocketClientEvent arg0) {
        System.out.println("opened");
    }

    public void processOpening(WebSocketClientEvent arg0) {
        System.out.println("opening");
    }

    public void processPacket(WebSocketClientEvent arg0, WebSocketPacket arg1) {
        System.out.println("packet");
    }

    public void processReconnecting(WebSocketClientEvent arg0) {
        System.out.println("reconnecting");
    }

    public void processToken(WebSocketClientEvent arg0, Token arg1) {
        System.out.println("token");
    }
}

so basically it’s just a spinner and a button. For now, all I want to do is connect to my local jWebSocketServer. The demo-app (the .apk package from the website, if I import the code eclipse tells me to remove many “@Overwrite” before it compiles the code – after that same “bug” occurs) works with my server so it has to be the code. Right now all I get is “connecting…” and about 0.1s later “closed”. Every time.

btw. the app has the right INTERNET and ACCESS_NETWORK_STATE so that shouldn’t be a problem.

i will be grateful for any help.

Cheers

  • 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-06T15:52:57+00:00Added an answer on June 6, 2026 at 3:52 pm

    Turns out, BaseTokenClient.open() is catching all exceptions and doing nothing about it (silent fail). In my case – NetworkOnMainThreadException. Mystery solved.

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

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.