I am trying to implement the library from http://www.aftek.com/afteklab/aftek-RTMP-library.shtml
to stream live video from a red5 server.
On the server i am using the simpleBroadcaster and i want to stream it to the android phone.
my code:
package com.cu.reader;
import java.nio.channels.FileChannel;
import java.util.Map;
import com.al.rtmp.client.RtmpClient;
import com.al.rtmp.client.RtmpStream;
import com.al.rtmp.client.RtmpStreamFactory;
import com.al.rtmp.client.data.MetaData;
import com.al.rtmp.client.data.RTMPData;
import com.al.rtmp.client.data.VideoCodec;
import com.al.rtmp.message.Metadata;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class StreamreaderActivity extends Activity implements RtmpClient {
RtmpStream stream = null;
Boolean connected = false;
String server = "rtmp://216.224.181.197/oflaDemo/";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
stream = RtmpStreamFactory.getRtmpStream();
stream.setClient(this);
stream.connect(server);
}
#Override
public void streamCreated() {
Log.i("stream","Connected!");
connected = true;
stream.setPlayName("red5StreamDemo");
stream.play();
}
#Override
public byte[] getWriteData(int length) {
// TODO Auto-generated method stub
return null;
}
#Override
public void invoke(String arg0, Object... arg1) {
// TODO Auto-generated method stub
;
}
#Override
public void onDataReceived(RTMPData rtmpData) {
MetaData metaData = rtmpData.getMetaData();
VideoCodec vc = metaData.getVideoCodec();
}
#Override
public void onError(Exception ex) {
Log.e("ClientException", " Some exception occurred." + ex.getMessage());
ex.printStackTrace();
}
#Override
public void onMetaDataReceived(Map map) {
Log.i("code","METADATA:" + map);
}
#Override
public void onResult(String method, Object... arg1) {
Log.i("result","METADATA:" + method);
}
#Override
public void onStatus(String code) {
Log.i("code",code);
}
}
i am always receiving NetStream.Play.StreamNotFound in onStatus function.
Thank you
You get NetStream.Play.StreamNotFound error becouse such stream doesnt exist on red5 application.
I made quick as3 test to check:
package {
import flash.display.Sprite;
import flash.events.AsyncErrorEvent;
import flash.events.IOErrorEvent;
import flash.events.NetStatusEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class LearnWowzaClient extends Sprite {
private var nc:NetConnection;
private var video:Video = new Video();
public function LearnWowzaClient() {
nc = new NetConnection();
nc.client = this;
nc.addEventListener(NetStatusEvent.NET_STATUS, onNet);
nc.connect("rtmp://216.224.181.197/oflaDemo/");
}
private function onNet(event:NetStatusEvent):void {
trace(event);
trace(event.info.code);
switch (event.info.code) {
case "NetConnection.Connect.Success":
tryPlayStream();
break;
}
}
private function tryPlayStream():void {
trace("playStream");
var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
ns.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
ns.play("red5StreamDemo");
video.attachNetStream(ns);
}
public function onBWCheck(parameter:Object = null):void {
trace("onBWCheck p=" + parameter);
}
public function onBWDone(parameter:Object = null):void {
trace("onBWDone p=" + parameter);
}
private function onIOError(event:IOErrorEvent):void {
trace("onIOError");
}
private function onAsyncError(event:AsyncErrorEvent):void {
trace("onAsyncError");
}
private function onNetStatus(event:NetStatusEvent):void {
trace("onNetStatus ", event.info.code);
}
}
}
I also get NetStream.Play.StreamNotFound error.
Can you show red5 application code?
The stream does not exist, correct. But why? Probably one or two reasons: you have not created a live broadcast stream and 2) because you are using the wrong scope. Unless you configure it differently by hand (which is unlikely), use the 'live' broadcaster scope, which is in /live.
Thus, publish to rtmp://216.224.181.197/live/red5StreamDemo and to subscribe to the exact same mrl, in this example rtmp://216.224.181.197/live/red5StreamDemo. NOTE: for this to work, you need to create a 'live' stream and feed it to your RED5 server. You can use avconv (aka ffmpeg) to create an rtmp feed.
Related
Url for the below Code : https://github.com/amankapur007/openflix_torrent
I am trying to convert https://github.com/TorrentStream/TorrentStream-Android to the flutter plugin .
I am able to start the stream and am also able to prepare it , but after that nothing happens , neither the download starts nor streaming start (Streaming i am not worried right now , moreover i want file download to start).
Please find the code below
package com.example.openflix_torrent;
import android.os.Environment;
import androidx.annotation.NonNull;
import com.github.se_bastiaan.torrentstream.StreamStatus;
import com.github.se_bastiaan.torrentstream.Torrent;
import com.github.se_bastiaan.torrentstream.TorrentOptions;
import com.github.se_bastiaan.torrentstream.TorrentStream;
import com.github.se_bastiaan.torrentstream.listeners.TorrentListener;
import java.io.File;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
/** OpenflixTorrentPlugin */
public class OpenflixTorrentPlugin implements FlutterPlugin, MethodCallHandler {
#Override
public void onAttachedToEngine(#NonNull FlutterPluginBinding flutterPluginBinding) {
final MethodChannel channel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "openflix_torrent");
channel.setMethodCallHandler(new OpenflixTorrentPlugin());
}
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "openflix_torrent");
channel.setMethodCallHandler(new OpenflixTorrentPlugin());
}
#Override
public void onMethodCall(#NonNull MethodCall call, #NonNull Result result) {
if (call.method.equals("getPlatformVersion")) {
init();
try {
Thread.sleep(1000);
start();
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
result.notImplemented();
}
}
#Override
public void onDetachedFromEngine(#NonNull FlutterPluginBinding binding) {
}
TorrentStream torrentStream;
public void init(){
TorrentOptions torrentOptions = new TorrentOptions.Builder()
.autoDownload(true)
.saveLocation(Environment.getDownloadCacheDirectory())
.removeFilesAfterStop(false)
.build();
this.torrentStream = TorrentStream.init(torrentOptions);
torrentStream.addListener(new TorrentListener() {
#Override
public void onStreamPrepared(Torrent torrent) {
System.out.println("onStreamPrepared");
}
#Override
public void onStreamStarted(Torrent torrent) {
System.out.println("onStreamStarted");
}
#Override
public void onStreamError(Torrent torrent, Exception e) {
System.out.println("onStreamError"+ e.getMessage());
}
#Override
public void onStreamReady(Torrent torrent) {
System.out.println("onStreamReady");
}
#Override
public void onStreamProgress(Torrent torrent, StreamStatus status) {
System.out.println("onStreamProgress");
}
#Override
public void onStreamStopped() {
System.out.println("onStreamStopped");
}
});
System.out.println("Initialized");
}
public void start(){
this.torrentStream.startStream("https://yts.lt/torrent/download/FF495923151031A547AE14C1CA9F0DFF8EA26A0B");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Started");
}
}
Please find the output
NOTE : init() and start() are called at the runtime .
Please find the github for the above code .
git#github.com:amankapur007/openflix_torrent.git
I am using libstreaming library and trying to stream with the RtspClient and the MedicaCodec API. I am testing with a galaxy s3 with android 4.4.
The problem is that no matter if I use buffer to buffer or surface to buffer I get this error : java.lang.IllegalStateException: The decoder input buffer is not big enough (nal=181322, capacity=65536). and java.lang.RuntimeException: The decoder did not decode anything. MediaRecorder api works fine but the quality is so low I can't tell if I have a cat or a dog in front of me.
Here is my code:
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.SurfaceHolder;
import net.majorkernelpanic.streaming.Session;
import net.majorkernelpanic.streaming.SessionBuilder;
import net.majorkernelpanic.streaming.audio.AudioQuality;
import net.majorkernelpanic.streaming.gl.SurfaceView;
import net.majorkernelpanic.streaming.rtsp.RtspClient;
import net.majorkernelpanic.streaming.video.VideoQuality;
import net.majorkernelpanic.streaming.MediaStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* A placeholder fragment containing a simple view.
*/
public class MainActivityFragment extends Fragment implements RtspClient.Callback,
Session.Callback, SurfaceHolder.Callback {
// surfaceview
private static SurfaceView mSurfaceView;
// Rtsp session
private Session mSession;
private static RtspClient mClient;
public MainActivityFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main, container, false);
mSurfaceView = (SurfaceView) view.findViewById(R.id.surface);
// Configures the SessionBuilder
mSession = SessionBuilder.getInstance()
.setContext(getActivity().getApplicationContext())
.setAudioEncoder(SessionBuilder.AUDIO_AAC)
.setAudioQuality(new AudioQuality(8000, 16000))
.setVideoEncoder(SessionBuilder.VIDEO_H264)
.setVideoQuality(new VideoQuality(960, 720, 20, 500000))
.setSurfaceView(mSurfaceView)
.setPreviewOrientation(0)
.setCallback(this)
.build();
// Configures the RTSP client
mClient = new RtspClient();
String ip, port, path;
// We parse the URI written in the Editext
Pattern uri = Pattern.compile("rtsp://(.+):(\\d+)/(.+)");
Matcher m = uri.matcher(AppConfig.STREAM_URL);
m.find();
ip = m.group(1);
port = m.group(2);
path = m.group(3);
mClient.setCredentials(AppConfig.PUBLISHER_USERNAME,
AppConfig.PUBLISHER_PASSWORD);
mClient.setServerAddress(ip, Integer.parseInt(port));
mClient.setStreamPath("/" + path);
mClient.setSession(mSession);
mClient.setCallback(this);
// Use this to force streaming with the MediaRecorder API
mSession.getVideoTrack().setStreamingMethod(MediaStream.MODE_MEDIACODEC_API_2);
mSurfaceView.getHolder().addCallback(this);
return view;
}
#Override
public void onDestroy() {
super.onDestroy();
mClient.release();
mSession.release();
mSurfaceView.getHolder().removeCallback(this);
}
#Override
public void onRtspUpdate(int message, Exception exception) {
switch (message) {
case RtspClient.ERROR_CONNECTION_FAILED:
case RtspClient.ERROR_WRONG_CREDENTIALS:
System.out.println(exception.getMessage());
exception.printStackTrace();
break;
}
}
#Override
public void onSessionError(int reason, int streamType, Exception e) {
switch (reason) {
case Session.ERROR_CAMERA_ALREADY_IN_USE:
break;
case Session.ERROR_CAMERA_HAS_NO_FLASH:
break;
case Session.ERROR_INVALID_SURFACE:
break;
case Session.ERROR_STORAGE_NOT_READY:
break;
case Session.ERROR_CONFIGURATION_NOT_SUPPORTED:
VideoQuality quality = mSession.getVideoTrack().getVideoQuality();
System.out.println("APPERROR: The following settings are not supported on this phone: " +
quality.toString()+" "+
"("+e.getMessage()+")");
e.printStackTrace();
break;
case Session.ERROR_OTHER:
break;
}
if (e != null) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
#Override
public void onPreviewStarted() {
mClient.startStream();
}
#Override
public void onSessionConfigured() {
}
#Override
public void onSessionStopped() {
}
#Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
mSession.startPreview();
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
mClient.stopStream();
}
#Override
public void onBitrateUpdate(long bitrate) {
}
#Override
public void onSessionStarted() {
}
}
Please Help! I'm desperate!
The request for more data came late but I found a solution. As many posts say I had to modify the libstreaming library. I changed:
public MediaStream() {
// code change
mRequestedMode = MODE_MEDIACODEC_API_2;
mMode = MODE_MEDIACODEC_API_2;
}
public synchronized void start() throws IllegalStateException, IOException {
if (mDestination==null)
throw new IllegalStateException("No destination ip address set for the stream !");
if (mRtpPort<=0 || mRtcpPort<=0)
throw new IllegalStateException("No destination ports set for the stream !");
mPacketizer.setTimeToLive(mTTL);
// code change
encodeWithMediaCodec();
}
AND had to call to surface method mSession.getVideoTrack().setStreamingMethod(MediaStream.MODE_MEDIACODEC_API_2); AND had to limit my config to these values: http://developer.android.com/guide/appendix/media-formats.html#recommendations
or it would crash or green screen or whatever.
Is it possible to intercept taking screenshot event (or create a listener for it) when my app is in the foreground? I want to execute some own code when a screenshot is taken by vol down+power key.
No, sorry, you do not get control on a screenshot. If your objective is to prevent your app from having a screenshot taken (e.g., security reasons), use FLAG_SECURE:
public class FlagSecureTestActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(LayoutParams.FLAG_SECURE,
LayoutParams.FLAG_SECURE);
setContentView(R.layout.main);
}
}
The way to do this task is to add a file observer on the screenshot directory. Writing sample code below to observe the file path
The screenshot file observer
package com.example.main;
import android.os.Environment;
import android.os.FileObserver;
import android.util.Log;
public class ScreenshotObserver extends FileObserver {
private static final String PATH = Environment.getExternalStorageDirectory().toString() + "/Pictures/Screenshots";
private static final String TAG = "ScreenshotObserver";
private ScreenshotListener listener;
private String mLastTakenPath;
ScreenshotObserver(ScreenshotListener listener) {
super(PATH);
this.listener = listener;
Log.d(TAG, PATH);
}
#Override
public void onEvent(int event, String path) {
Log.d(TAG, String.format("Detected new file added %s", path));
if (path==null || event != FileObserver.CLOSE_WRITE)
Log.d(TAG, "Don't care.");
else if (mLastTakenPath!=null && path.equalsIgnoreCase(mLastTakenPath))
Log.d(TAG, "This event has been observed before.");
else {
mLastTakenPath = path;
listener.onScreenshotTaken(path);
Log.d(TAG, "Send event to listener.");
}
}
public void start() {
super.startWatching();
Log.d(TAG, "Start Watching.");
}
public void stop() {
super.stopWatching();
Log.d(TAG, "Stop Watching.");
}
}
Activity that implement the file observer
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity implements ScreenshotListener{
private ScreenshotObserver obs;
#Override
protected void onCreate( Bundle savedInstanceState ) {
super.onCreate(savedInstanceState);
obs = new ScreenshotObserver(this);
obs.start();
setContentView(R.layout.activity_main);
}
#Override
public void onScreenshotTaken( String path ) {
TextView t = (TextView)findViewById(R.id.monText);
t.setText("Screenshot taken ! " + path);
}
}
Sorry for my english.
I want to program a native app in Android to connect with a server for interactive comunications. Websocket tegnology is perfect fothis. I have installed and working Tomcat 7.0.39 in my laptop with IP 192.168.1.250. I have tryed the examples echo, snake, etc and it works fine using ws://localhost:8080/.... and using ws://192.168.1.250:8080/...
I'm using autobahn with eclipse to connect to my server. I have installed apk in my Android mobile with autobahn client websocket sample and it connects perfectly withn ws://echo.websocket.org.
The problem is that from android to my server (in my laptop) not work. From android to ws://echo.websocket.org works fine (I supose that autobahn example works well), my server works fine because de examples comes with tomcat work fine.
Because I have to make intesive work with information that travel between server and clients, I can't use javascript on server side, I need java servlets or others to work with databases, files ando so on.
What is wrong? Firewall is off, and wireshark show me how android client try to connect to my laptop server ( I don't anderstand wireshark info well ) but the connection loses.
This my android code:
package com.example.autobahnandroiddemo;
import de.tavendo.autobahn.WebSocketConnection;
import de.tavendo.autobahn.WebSocketException;
import de.tavendo.autobahn.WebSocketHandler;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
static final String TAG = "de.tavendo.autobahn.echo";
private static final String PREFS_NAME = "AutobahnAndroidEcho";
static EditText mHostname;
static EditText mPort;
static TextView mStatusline;
static Button mStart;
static EditText mMessage;
static Button mSendMessage;
private SharedPreferences mSettings;
private void alert(String message) {
Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
private void loadPrefs() {
mHostname.setText(mSettings.getString("hostname", ""));
mPort.setText(mSettings.getString("port", "9000"));
}
private void savePrefs() {
SharedPreferences.Editor editor = mSettings.edit();
editor.putString("hostname", mHostname.getText().toString());
editor.putString("port", mPort.getText().toString());
editor.commit();
}
private void setButtonConnect() {
mHostname.setEnabled(true);
mPort.setEnabled(true);
mStart.setText("Connect");
mStart.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
start();
}
});
}
private void setButtonDisconnect() {
mHostname.setEnabled(false);
mPort.setEnabled(false);
mStart.setText("Disconnect");
mStart.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
mConnection.disconnect();
}
});
}
private final WebSocketConnection mConnection = new WebSocketConnection();
private void start() {
final String wsuri = mHostname.getText() + ":" + mPort.getText();
mStatusline.setText("Status: Connecting to " + wsuri + " ..");
setButtonDisconnect();
try {
mConnection.connect(wsuri, new WebSocketHandler() {
#Override
public void onOpen() {
mStatusline.setText("Status: Connected to " + wsuri);
savePrefs();
mSendMessage.setEnabled(true);
mMessage.setEnabled(true);
}
#Override
public void onTextMessage(String payload) {
alert("Got echo: " + payload);
}
#Override
public void onClose(int code, String reason) {
alert("Connection lost.");
mStatusline.setText("Status: Ready.");
setButtonConnect();
mSendMessage.setEnabled(false);
mMessage.setEnabled(false);
}
});
} catch (WebSocketException e) {
Log.d(TAG, e.toString());
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mHostname = (EditText) findViewById(R.id.hostname);
mPort = (EditText) findViewById(R.id.port);
mStatusline = (TextView) findViewById(R.id.statusline);
mStart = (Button) findViewById(R.id.start);
mMessage = (EditText) findViewById(R.id.msg);
mSendMessage = (Button) findViewById(R.id.sendMsg);
mSettings = getSharedPreferences(PREFS_NAME, 0);
loadPrefs();
setButtonConnect();
mSendMessage.setEnabled(false);
mMessage.setEnabled(false);
mSendMessage.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
mConnection.sendTextMessage(mMessage.getText().toString());
}
});
}
#Override
protected void onDestroy() {
super.onDestroy();
if (mConnection.isConnected()) {
mConnection.disconnect();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.quit:
finish();
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
}
AND THIS IS MY SERVLET TOMCAT CODE:
package servlets;
import org.apache.catalina.websocket.MessageInbound;
import org.apache.catalina.websocket.StreamInbound;
import org.apache.catalina.websocket.WebSocketServlet;
import org.apache.catalina.websocket.WsOutbound;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
public class SimpleWebSocketServlet extends WebSocketServlet {
private static final long serialVersionUID = 1L;
#Override
protected StreamInbound createWebSocketInbound(String string, HttpServletRequest hsr) {
return new MessageInbound() {
#Override
protected void onBinaryMessage(ByteBuffer bb) throws IOException {
}
#Override
protected void onTextMessage(CharBuffer cb) throws IOException {
System.out.println(cb.toString());
WsOutbound outbound = getWsOutbound();
outbound.writeTextMessage(cb);
}
};
}
}
I don't know what's wrong. Have another solution to use android client in conjuntion with server (java servlets on similar tecnology) through websockets?
Thanks
I think you should have put the code of connecting into onCreate.
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
Turns out, BaseTokenClient.open() is catching all exceptions and doing nothing about it (silent fail). In my case - NetworkOnMainThreadException. Mystery solved.