Java/Kotlin (Android Studio)
Using Java
Download .jar library
Download the NEP Java library using the next link:
Include .jar library
Copy .jar to the "libs" Directory: Navigate to the apps/libs directory in the Android Studio project and copy and paste the .jar file, such as the figure below.

Include the required
.jarfile in Your Project: In Android Studio open build.gradle(Module:app) located in Grandle Scripts -> build.gradle and the next dependencies:
Sync Gradle Files: Click on the "Sync Project with Gradle Files" button in the toolbar. This action ensures that the newly added library is properly included in your project's build configuration.
Verify the Gradle Sync: Once the Gradle sync is complete, verify that there are no errors in the Gradle console.
Configure Network Permissions: Since your app will be using network sockets, you need to ensure that your AndroidManifest.xml file includes the necessary permissions. Add the following permission to your manifest file:
Create a simple publisher:
Import NEP libraries to the MainActivity file as follows:
Modify the MainActivity class as follows:
Update nepMasterIP (line 6) with the IP address of the computer running the NEP master server (using NEP-CLI or NEP+ App).
Add a button in activity_main.xml and inside the XML layout (code ) file set its onClick attribute to execute a function named onClickBtn
In this example onClick attribute is set in line 5.
Add a simple subscriber:
For this example, we need to import the next packages/libraries:
To the previous code, we will add a background thread or AsyncTask to perform socket communication operations. AsyncTask is a convenient way to perform background tasks and update the UI thread with the results.
Here's an example of how you can define an AsyncTask to handle socket communication:
After defining the AsyncTask, you can create an instance of it and execute it to start listening to the subscriber. You can execute the AsyncTask in the onCreate() method of your Activity or wherever appropriate.
Ensure that you properly handle cleanup when your AsyncTask is no longer needed. You can cancel the AsyncTask and clean up resources in the onDestroy() method of your Activity or wherever appropriate.
An example of putting it all together is shown below:
Using Koltin (Soon ...)
Last updated