Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jerryting/base-nio
Browse files Browse the repository at this point in the history
  • Loading branch information
lisangang authored and lisangang committed Mar 28, 2016
2 parents c490f87 + 2f18057 commit 584d245
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 3 deletions.
86 changes: 85 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,85 @@
# basenio
# BaseNIO
***

After learning [ApacheMina](http://mina.apache.org/),we provide this java Non-blocking IO (**NIO**) mini framework. Thanks for MINA's so excellent work.

Using this frame,you can build a TCP server for accepting TCP client channel connection request. and that , process socket read\write.

and others. we also provide TCP client and UDP server\client. details in those codes */src/main/java/test*

##Important notice

Basenio does not implements any protocol base on tcp or udp, It transfer all data by **BYTE** for what is whether server or client. and so, you must package any protocol what you want


##How to use

> Firstly you must deeply read the demo codes in **/src/main/java/test**
* get all source codes, and then use MAVEN build a jar package ,import this jar package to your project.
* directly use we provided the lastest release jar.

##Application Scenarios

* high performance TCP server based on byte protocol.
* One flexible TCP client that can connect to a tcp server , and transfer byte data.
* A UDP client that send a bound byte message .
* UDP server listen udp port ,receive byte message. and others, it can be used to be an UDP broadcast.

##Examples
*the following codes is a TCP server usage , please look up other usages in domo samples。*

package test;
import java.net.InetSocketAddress;
import com.polarlight.commons.basenio.io.NioSocketServerAccepter;

public class ServerDemo {

public static void main(String[] args) throws InterruptedException {
try {
/** initialize instance **/
NioSocketServerAccepter nioserv = new NioSocketServerAccepter();
/**set callback object*/
nioserv.setHandler(new ServerHandler());
/**set session buffer size (byte)*/
nioserv.setSessionBufSize(1024);
/**session idle timespan (ms)*/
nioserv.setMaxSessionIdleMS(30000 * 1000);
/*server startup*/
nioserv.bind(new InetSocketAddress("0.0.0.0", 4567));
/*this is only a explain for using shutdown method */
Thread.sleep(1000000);
nioserv.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
}

***

package test;

import java.io.IOException;
import java.util.Arrays;

import com.polarlight.commons.basenio.exception.NioBaseWriteException;
import com.polarlight.commons.basenio.io.session.state.IoStateSession;
import com.polarlight.commons.basenio.service.IoHandler;

public class ServerHandler implements IoHandler {
@Override
public void socketCreated(IoStateSession session) {
System.out.println(session.toString() + " [server] enter into channel");
}

@Override
public void socketClosed(IoStateSession session) {
System.out.println(session.toString() + "[server] closed");
}

@Override
public void messageReceived(IoStateSession session, byte[] message) {
System.out.println("[server] rev: " + session + " " + Arrays.toString(message));
}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @author : DJ@201509
* @author : DJ@201509 11
* @summary: Java application 's gradle build script
* @cmd & task: gradle build
* gradle eclipse
Expand Down Expand Up @@ -101,7 +101,7 @@ task versionInfo <<{
}

task svnTag (type: at.bxm.gradleplugins.svntools.tasks.SvnTag){
svnUrl = 'http://192.168.1.101/svn/polarlight/trunk/client-android/basenio-2.0-beta'
//svnUrl = 'http://192.168.1.101/svn/polarlight/trunk/client-android/basenio-2.0-beta'
username = authSvnUser
password = authSvnPwd
def tagPath = "basenio-2.0/"
Expand Down

0 comments on commit 584d245

Please sign in to comment.