This Android app allows users to establish a network connection and send messages to a server. The app uses Kotlin, Android Jetpack components, and follows the Model-View-ViewModel (MVVM) architectural pattern. The server app is written in Python Flask and can be found in one of my other repositories.
Server App Repository with Python Flask
- Connect to a server via IP address
- Send messages to the server
- Show connection status
- Option to manually enter the server's IP address
- Reset connection
- Kotlin programming language
- Android Jetpack components (ViewModel, LiveData, Data Binding, and Lifecycle components)
- AndroidX libraries
- Material Components for Android
- Coroutine for asynchronous tasks
- Java Sockets for network communication
- Model-View-ViewModel (MVVM)
The app consists of the following main components:
Commons
class: A utility class with a companion object that contains a functionintToIp
which converts an integer to an IP address.Constants
object: A singleton object that stores constants such as the connection timeout, port, and socket timeout.MainViewModel
class: A ViewModel class that extendsViewModel
and contains LiveData objects to manage and store the application's UI data. It also contains a few variables for user input.MainActivity
class: AnAppCompatActivity
that handles the UI interactions and works with theMainViewModel
. It sets up views, listeners, and shared preferences, and manages the network connection using aNetworkManager
object.NetworkManager
class: A custom class responsible for managing the network connection, connecting to the server, and sending messages using Java Sockets.
- Clone the repository
- Open the project in Android Studio
- Build and run the app on an emulator or a physical device
- The app will display a connection warning dialog on the first run. Press "OK" to proceed.
- The app will attempt to establish a connection to the server. If successful, you can send messages to the server using the "Send" button.
- You can manually enter the server's IP address by checking the "Manual IP" checkbox.
- To reset the connection, click on the menu icon in the top right corner and select "Reset Connection".
Note: Ensure that the server is running and accessible when using the app. Find the Python Flask server app in one of my other repositories: Server App Repository with Python Flask