-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c1cd0e
commit 7134f64
Showing
15 changed files
with
274 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
.idea/runConfigurations/io_github_naveenb2004_SampleProject_Main.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2024 Naveen Balasooriya | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.github.naveenb2004</groupId> | ||
<artifactId>SampleProject</artifactId> | ||
<version>1.1.0</version> | ||
|
||
<name>SampleProject</name> | ||
<description>Sample codes for Socket Data Handler!</description> | ||
<url>https://github.com/NaveenB2004/SocketDataHandler</url> | ||
<inceptionYear>2024</inceptionYear> | ||
|
||
<properties> | ||
<java.version>11</java.version> | ||
<maven.compiler.source>${java.version}</maven.compiler.source> | ||
<maven.compiler.target>${java.version}</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<!-- dependency versions --> | ||
<ver.lombok>1.18.30</ver.lombok> | ||
<ver.SocketDataHandler>1.1.0</ver.SocketDataHandler> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>${ver.lombok}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.naveenb2004</groupId> | ||
<artifactId>SocketDataHandler</artifactId> | ||
<version>1.1.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Apache License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<id>NaveenB2004</id> | ||
<name>Naveen Balasooriya</name> | ||
<email>[email protected]</email> | ||
<url>https://github.com/NaveenB2004</url> | ||
<timezone>UTC+05:30</timezone> | ||
<properties> | ||
<!-- messenger platform --> | ||
<Telegram>https://t.me/NaveenB2004</Telegram> | ||
</properties> | ||
</developer> | ||
</developers> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
# User guids for Socket Data Handler | ||
|
||
- [User guids for Socket Data Handler](#user-guids-for-socket-data-handler) | ||
- [Import into the project](#import-into-the-project) | ||
- [Common library settings](#common-library-settings) | ||
- [Setting up the receiver](#setting-up-the-receiver) | ||
- [Connect socket and library](#connect-socket-and-library) | ||
- [Receiving pre-updates](#receiving-pre-updates) | ||
- [Send data](#send-data) | ||
- [Close socket](#close-socket) | ||
|
||
## Import into the project | ||
|
||
[![Central Repository](https://img.shields.io/maven-central/v/io.github.naveenb2004/SocketDataHandler | ||
)](https://central.sonatype.com/artifact/io.github.naveenb2004/SocketDataHandler) | ||
[![Minimum JDK version](https://img.shields.io/badge/Minumum_JDK-v11-green)](#)\ | ||
If you are using project managers like `Maven`, `Gradle` etc., please take a look at | ||
the [Central repository page for this project](https://central.sonatype.com/artifact/io.github.naveenb2004/SocketDataHandler). | ||
You can find most of the import snippets for project managers from there. For `Maven`: | ||
|
||
```xml | ||
|
||
<dependency> | ||
<groupId>io.github.naveenb2004</groupId> | ||
<artifactId>SocketDataHandler</artifactId> | ||
<version><!-- set version --></version> | ||
</dependency> | ||
``` | ||
|
||
## Common library settings | ||
|
||
In this library, you can set up maximum IO buffer size for data chunks (in `bytes`) and default location for work | ||
with `Files`. To do that place this code before any initialization of the `SocketDataHandler`. | ||
|
||
```java | ||
// set default maximum buffer size for chunks | ||
SocketDataHandler.setDefaultBufferSize(1024); | ||
|
||
// set default temporary folder for files downloading | ||
SocketDataHandler.setTempFolder(new File("Temp")); | ||
``` | ||
|
||
## Setting up the receiver | ||
|
||
Now you're good to code your receiver file. To do that, make a class that `extends` the `SocketDataHandler` and | ||
implement the required constructors and methods in that class. | ||
|
||
> MySocket.java | ||
```java | ||
public class MySocket extends SocketDataHandler { | ||
public MySocket(Socket SOCKET) { | ||
super(SOCKET); | ||
} | ||
|
||
@Override | ||
public void onUpdateReceived(DataHandler update) { | ||
|
||
} | ||
|
||
@Override | ||
public void onDisconnected(DataProcessor.DisconnectStatus status, Exception exception) { | ||
|
||
} | ||
} | ||
``` | ||
|
||
All completed updates are pushed to the `onUpdateReceived(DataHandler update)` method and if socket disconnected (either | ||
end) it will push to `onDisconnected(DataProcessor.DisconnectStatus status, Exception exception)` method. | ||
|
||
## Connect socket and library | ||
|
||
`SocketDataHandler` is just a library to manage socket IO operations. So you need to work on your network operations. | ||
|
||
```java | ||
// connect to the server | ||
Socket socket = new Socket("localhost", port); | ||
|
||
// connect socket with library | ||
MySocket clientSocket = new MySocket(socket); | ||
``` | ||
|
||
## Receiving pre-updates | ||
|
||
`Pre-update` means that uncompleted, processing (receiving or sending) update. You can only get pre-updates | ||
for `Serializable Objects` and `Files`. To do that you need to implement a `pre-updates watcher` class and register it | ||
with the `receiver` class that `extends` the `SocketDataHandler`. | ||
|
||
> MyPreUpdateWatcher.java | ||
```java | ||
public class MyPreUpdateReceiver implements PreUpdateWatcher { | ||
@Override | ||
public void onPreUpdateSeen(PreDataHandler preUpdate) { | ||
|
||
} | ||
} | ||
``` | ||
|
||
> MySocket.java | ||
```java | ||
public class MySocket extends SocketDataHandler { | ||
public MySocket(Socket SOCKET) { | ||
super(SOCKET); | ||
// register the watcher | ||
PreUpdateHandler watcher = getPRE_UPDATE_HANDLER(); | ||
watcher.addWatcher(new MyPreUpdateReceiver()); | ||
} | ||
|
||
@Override | ||
public void onUpdateReceived(DataHandler update) { | ||
|
||
} | ||
|
||
@Override | ||
public void onDisconnected(DataProcessor.DisconnectStatus status, Exception exception) { | ||
|
||
} | ||
} | ||
``` | ||
|
||
## Send data | ||
|
||
You can use `DataHandler` object to store your request and use `send` method to send it. Note that the `send` method is | ||
part of your receiver class that `extends` with the `SocketDataHandler`. | ||
|
||
```java | ||
DataHandler dataHandler = new DataHandler("/SendText"); | ||
try { | ||
clientSocket.send(dataHandler); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
``` | ||
|
||
## Close socket | ||
|
||
You can either direct close the socket or use `close` method of your receiver class that `extends` with | ||
the `SocketDataHandler`. On successful close, you will receive an update for `onDisconneted`. | ||
|
||
```java | ||
try { | ||
clientSocket.close(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters