mocket
Release for testing on android things
Lightweight, Typesafe, Reliable, Guaranty delivery, Ordered, High performant java nio sockets build
on top of udp.
아래와 같이:
< project >
...
< repositories >
...
< repository >
< id >jitpack.io</ id >
< url >https://jitpack.io</ url >
</ repository >
</ repositories >
</ project >
< dependencies >
...
< dependency >
< groupId >com.github.Nishant-Pathak</ groupId >
< artifactId >mocket</ artifactId >
< version >v1.0</ version >
</ dependency >
</ dependencies >
allprojects {
repositories {
.. .
maven { url ' https://jitpack.io ' }
}
}
dependencies {
compile ' com.github.Nishant-Pathak:mocket:v1.0 '
}
서버를 구축하려면:
ServerBuilder < byte []> serverBuilder = new ServerBuilder < byte []>()
. port ( serverPort );
Server < byte []> server = serverBuilder . build ();
읽으려면:
while ( true ) {
// blocking read
Pair < SocketAddress , byte []> readBytes = server . read ();
}
작성하려면:
// write to server
server . write ( read . getSecond (), read . getFirst ());
서명 쓰기:
/**
* writed data to the given address
* @param data to send to addredd
* @param address of the client connected
* @throws IOException if error occurs while writing to the socket
* @throws InterruptedException if write is interrupted
*/
void write ( T data , SocketAddress address ) throws IOException , InterruptedException ;
클라이언트를 구축하려면:
ClientBuilder < byte []> builder = new ClientBuilder < byte []>()
. host ( "127.0.0.1" , 8080 );
Client < byte []> client = builder . build ();
읽으려면:
// blocking read
byte [] data = client . read ();
작성하려면:
client . write ( data );
서명 쓰기:
/**
* write object of type T on the wire
* it used @{@link com.network.mocket.handler.MocketStreamHandler} to parse the object
* @param data object to send on wire to the server.
* @throws IOException if error occurs while writing to the socket
* @throws InterruptedException if write is interrupted
*/
void write ( T data ) throws IOException , InterruptedException ;
Java 인터페이스를 구현하고 이를 클라이언트 및 서버 빌더에 다음과 같이 추가합니다.
builder . addHandler ( new MyCustomHandler ())
public interface MocketStreamHandler < P > {
/**
* Used to encode object to byte stream
* @param in inout object of tye {P}
* @return byte array representing object
* @throws ParseException throws if fails to encode or decode
*/
byte [] encode ( P in ) throws ParseException ;
/**
* Used to decode bytestream to object
* @param out inout object of tye {P}
* @return byte array representing object
* @throws ParseException throws if fails to encode or decode
*/
P decode ( byte [] out ) throws ParseException ;
}
샘플 서버 클라이언트는 여기에서 찾을 수 있습니다.
*일부 게이트웨이는 UDP 트래픽을 차단할 수 있습니다.
나는 피드백, 버그 보고서, 그리고 더 나은 풀 요청의 형태로 프로젝트에 대한 외부 기여를 받아들이는 것을 매우 기쁘게 생각합니다 :)
끌어오기 요청을 제출하려면 CONTRIBUTING.md의 가이드를 따르도록 노력하세요.
저작권 (C) 2016 - 2017 Nishant Pathak
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.