android-socket | android socket 客服端与服务器进行数据通信 | Socket library
kandi X-RAY | android-socket Summary
kandi X-RAY | android-socket Summary
android socket 客服端与服务器进行数据通信
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Main loop
- Connect to server
- Show a dialog
- Click button
- Start a connection
- Send socket
- Initialize the demo
- Initialize textView
- Initialize view
- Start activity button
- Initializes the view
android-socket Key Features
android-socket Examples and Code Snippets
Community Discussions
Trending Discussions on android-socket
QUESTION
First off, I'm a complete newbie to Android, Java and posting on Stacks Overflow so apologies if I'm doing anything wrong!
I'm trying to create a simple app for a project that utilises sockets. I want to set up a client on an Android device that sends commands to a server running on a PC. I've written my server in Python and have tested it, so I know that side of the project works. I'm having issues with the implementation of the Android app.
I followed this guide to write my client app: https://examples.javacodegeeks.com/android/core/socket-core/android-socket-example/
When I run my app, my server acknowledges that a client has connected to it. However, when I try to send data, nothing is received by the server. This is what my code looks like (it's pretty much the same as that in the link above):
MainActivity.java
...ANSWER
Answered 2017-Jun-24 at 18:54I'm surprised you aren't crashing. The click handler runs on the main thread. The main thread can't do network IO- it should throw an exception to try. The BufferedWriter might be saving you there- it may not be writing to the actual socket and buffering everything if the messages are small, because you aren't flushing the stream.
So the first thing you need to do is do the writes on another thread- probably your ClientThread, and use some form of message passing to send write commands to it. The second thing you need is to simplify your output writers- you really don't need to wrap it in anything, just writing directly to the output stream is sufficient for your use.
QUESTION
I'm trying to test if my Android App is connecting to a Rpi hot spot. I'm following this guide for the client code.
I want to have a toast message pop up depending on the state of socket.isConnected() when I hit a button. However, I think each time I try and implement it, I run into Network on the main thread problems. How could I change the following code to add a simple "if(true), send toast message" using the isConnected method in the onClick?
Thank you for any help!
...ANSWER
Answered 2017-Feb-24 at 04:59onClick
is called on main Thread.So you are writing to socket(Network Operation) on main thread which is causing problem. Your below code should run on background thread.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install android-socket
You can use android-socket like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the android-socket component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page