A minimal Android app (Java) that opens a TCP socket to a server on the local network, sends a line of text, and shows the server's one-line reply in a toast. Written as the client side of a networking course milestone (project name mileston0).
- Connect button opens a
java.net.Socketto a hard-coded host and port (192.168.43.226:8888). - Send button writes the text from the input field followed by a newline (
DataOutputStream.writeBytes), then reads one line back (BufferedReader.readLine) and displays it asFROM SERVER: <reply>.
The server is not part of this repository; any TCP server that reads a line and answers with a line will work.
- Socket connect, send and receive run on the UI thread. Android blocks network calls on the main thread by default (
NetworkOnMainThreadException), so they would need to move to a background thread for the app to work on current Android versions. - Host and port are hard-coded in
client.java.
- Java, Android SDK (compileSdk/targetSdk 32, minSdk 28)
- Android Support Library (
appcompat-v7,constraint-layout) java.net.Socket(TCP)
app/
├── build.gradle
└── src/main/
├── AndroidManifest.xml # INTERNET + ACCESS_NETWORK_STATE permissions
├── java/com/example/mileston0/client.java # the only activity
└── res/layout/activity_main.xml # text field, "connect" and "send" buttons
- Start a line-based TCP server on a machine in the same network.
- Change
hostNameandportNumberinclient.javato match it. - Open the project in Android Studio and run it on a device on that network; tap connect, type a message, tap send.
Developed by Khaled Walid