All Projects → samigehi → AsyncSocket

samigehi / AsyncSocket

Licence: MIT license
Asynchronous socket (client+server) continues communications

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to AsyncSocket

workerman
An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols. PHP>=5.4.
Stars: ✭ 10,005 (+38380.77%)
Mutual labels:  socket, socket-server
Oksocket
An blocking socket client for Android applications.
Stars: ✭ 2,359 (+8973.08%)
Mutual labels:  socket, socket-server
T Io
解决其它网络框架没有解决的用户痛点,让天下没有难开发的网络程序
Stars: ✭ 1,331 (+5019.23%)
Mutual labels:  socket, nio
realgpserver
程序采用Python语言进行编写开发,用来接收GPS原始数据,并进行解析入库Mysql。主要用到SocketServer,log,command,dbhandler,config几个模块。
Stars: ✭ 13 (-50%)
Mutual labels:  socket, socket-server
ExpressJS-SocketIO-Boilerplate
📦 Simple Express.js & Socket.io Boilerplate
Stars: ✭ 31 (+19.23%)
Mutual labels:  socket, socket-server
Workerman
An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols. PHP>=5.3.
Stars: ✭ 9,617 (+36888.46%)
Mutual labels:  socket, socket-server
Nettychat
基于Netty+TCP+Protobuf实现的Android IM库,包含Protobuf序列化、TCP拆包与粘包、长连接握手认证、心跳机制、断线重连机制、消息重发机制、读写超时机制、离线消息、线程池等功能。
Stars: ✭ 1,979 (+7511.54%)
Mutual labels:  socket, nio
as2-server
A standalone Java AS2 server - see as2-lib for the generic parts
Stars: ✭ 29 (+11.54%)
Mutual labels:  socket, socket-server
go-eventserver
A socket server which reads events from an event source and forwards them to the user clients when appropriate
Stars: ✭ 18 (-30.77%)
Mutual labels:  socket, socket-server
ezyfox-server-flutter-client
a flutter socket client sdk for ezyfox-server
Stars: ✭ 44 (+69.23%)
Mutual labels:  socket, socket-client
Jupiter
Jupiter是一款性能非常不错的, 轻量级的分布式服务框架
Stars: ✭ 1,372 (+5176.92%)
Mutual labels:  socket, nio
cAndroid
cAndroid is tool for control your PC by Android phone
Stars: ✭ 23 (-11.54%)
Mutual labels:  socket, client-server
micrOS
micrOS - mini automation OS for DIY projects requires reliable direct communication
Stars: ✭ 55 (+111.54%)
Mutual labels:  socket, socket-client
aioudp
Asyncio UDP server
Stars: ✭ 21 (-19.23%)
Mutual labels:  socket, socket-server
sockerl
Sockerl is an advanced Erlang/Elixir socket framework for TCP protocols and provides fast, useful and easy-to-use API for implementing servers, clients and client connection pools.
Stars: ✭ 26 (+0%)
Mutual labels:  socket, socket-server
UDPSender
UDPSender 一个基于NIO的UDP发送-接收器
Stars: ✭ 34 (+30.77%)
Mutual labels:  nio
express-boilerplate
ExpressJS boilerplate with Socket.IO, Mongoose for scalable projects.
Stars: ✭ 83 (+219.23%)
Mutual labels:  socket
ShiTTYchat
A bare-bones terminal chat room.
Stars: ✭ 24 (-7.69%)
Mutual labels:  client-server
react-express-jwt
Example NodeJS, Express, Mongoose, React app with JWT auth for beginners WITHOUT redux.
Stars: ✭ 51 (+96.15%)
Mutual labels:  client-server
net-Socket
A minimalist wrapper around System.Net.Sockets.Socket.
Stars: ✭ 21 (-19.23%)
Mutual labels:  socket

AsyncSocket

Asynchronous socket (client+server) continues communications

A java library which used SocketChannels to communicate with server in non-blocking way I/O endpoints and totally based on NIO, used Buffer to send and retrieve data from server. Open multiple connections at once.

Features

  • Based on NIO. One thread, driven by callbacks. Highly efficient.
  • All operations return a Future that can be cancelled
  • Socket client + socket server
  • HTTP client + server
  • Used java Socket and SocketChannel (non-blocking way)
  • Fast and continues emit data from server when available
  • Thread optimized, easy to use, Byte Buffer optimized
  • ~65KB

USAGE

Import

dependencies {
  implementation 'com.samigehi:socket:1.0'
}

Java

connect using helper class (easy and recommended)

 private final SocketHelper helper = new SocketHelper("127.0.0.1", 1236);
  
  
// later...
// check if connected or wifi-on
helper.connect(new SocketListener() {

           @Override
           public void onConnect(AsyncSocket socket) {
               // on successfully connected to server
           }

           @Override
           public void onError(Exception error) {
               // when an error occurred
               error.printStackTrace();
           }

           @Override
           public void onClosed(Exception error) {
               // when connection closed by server or an error occurred to forcefully close server connection
           }

           @Override
           public void onDisconnect(Exception error) {
               // when connection closed by server or self closed by calling disconnect
           }

           @Override
           public void onDataWrite(String message, Exception error) {
               // notify when data successfully sent to server
               Log.d("SocketHelper", "onDataWrite >> " + message);
               if (error != null)
                   error.printStackTrace();
           }

           @Override
           public void onDataReceived(String message, DataEmitter emitter) {
               // notify when new data received from server
               Log.d("SocketHelper", "onDataReceived >> " + message);
               if (message.startsWith("~Login")) {
                   // Request  LOGIN
               } else if (message.startsWith("~OTP")) {
                   // Request OTP
               } else if (message.startsWith("...")) {
                   // Request any?
               }
           }
       });

Send/Write data to server from anywhere throught app using sinleton

// delay in milis
helper.send("~LOGIN|ABCD|EFG|h|$$", delay);

OR

connect using base SocketServer class (for advance users)

final SocketServer server = SocketServer.getDefault();
        server.connectSocket("127.0.0.1", 8080, new ConnectCallback() {
            @Override
            public void onConnectCompleted(Exception ex, AsyncSocket socket) {
                if (ex != null) {
                    ex.printStackTrace();
                }
                if (socket == null) {
                    //not connected yet return
                    return;
                }
                // connected
                socket.setDataCallback(new DataCallback() {
                    @Override
                    public void onDataAvailable(DataEmitter emitter, ByteBufferReader bb) {
                        // triggered when new data available from server
                    }
                });

                socket.setWriteableCallback(new WritableCallback() {
                    @Override
                    public void onWriteable() {
                        // when something write/sent to server
                    }
                });

                socket.setClosedCallback(new CompletedCallback() {
                    @Override
                    public void onCompleted(Exception ex) {
                        // when connection closed
                    }
                });

                socket.setEndCallback(new CompletedCallback() {
                    @Override
                    public void onCompleted(Exception ex) {
                        // when connection ended
                    }
                });
            }
        });
        
        
        
        // later write to server.....
         SocketServer.getDefault().post(new Runnable() {
            @Override
            public void run() {
                // white data to server
                Util.writeAll(socketRef, dataToWrite, new CompletedCallback() {
                    @Override
                    public void onCompleted(Exception ex) {

                    }
                });
            }
        });

This library is typical for those applications which require continues client-server communications

THANKS

Thanks to @Koush

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].