Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ws.connect causes error... #182

Closed
dinalt2006 opened this issue May 14, 2019 · 4 comments
Closed

ws.connect causes error... #182

dinalt2006 opened this issue May 14, 2019 · 4 comments

Comments

@dinalt2006
Copy link

dinalt2006 commented May 14, 2019

It's my code

       WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(100);
        try {
            ws = factory.createSocket("wss://echo.websocket.org/");
            ws.addListener(new WebSocketAdapter() {
                @Override
                public void onTextMessage(WebSocket websocket, String message) throws Exception {
                    SendBrodcastMessage(message);
                }
            });
            try
            {
                ws.connect();
            }
            catch (Exception e) {
                String msg = e.toString();
                Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

It causes this error : android.os.NetworkOnMainThreadException
Please, catch my error ...

@afarber
Copy link

afarber commented May 14, 2019

Do not run your code on the main thread

@dinalt2006
Copy link
Author

I try this code in Service at first. Unfortunately, with same error !!
Doe's exist working any working example for this winsock library?

@afarber
Copy link

afarber commented May 15, 2019

Service runs in main thread

@TakahikoKawasaki
Copy link
Owner

@dinalt2006
If you still see NetworkOnMainTheadException even if you avoid calling connect() from within the main thread and even if you make sure listener methods are not called from within the main thread, please let me know again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants