jdk1.7支持sctp协议,需要linux安装sctp支持库

测试代码

 public class ServerSCTP {
static int SERVER_PORT = 3456;
static int US_STREAM = 0;
static int FR_STREAM = 1; static SimpleDateFormat USformatter = new SimpleDateFormat("h:mm:ss a EEE d MMM yy, zzzz", Locale.US);
static SimpleDateFormat FRformatter = new SimpleDateFormat("h:mm:ss a EEE d MMM yy, zzzz", Locale.FRENCH); @SuppressWarnings("restriction")
public static void main(String[] args) throws IOException {
com.sun.nio.sctp.SctpServerChannel ssc = com.sun.nio.sctp.SctpServerChannel.open();
ssc.bind(new InetSocketAddress(SERVER_PORT)); ByteBuffer buf = ByteBuffer.allocateDirect(60);
CharBuffer cbuf = CharBuffer.allocate(60);
CharsetEncoder encoder = Charset.forName("ISO-8859-1").newEncoder(); while (true) {
com.sun.nio.sctp.SctpChannel sc = ssc.accept(); /* get the current date */
Date today = new Date();
cbuf.put(USformatter.format(today)).flip();
encoder.encode(cbuf, buf, true);
buf.flip(); /* send the message on the US stream */
com.sun.nio.sctp.MessageInfo messageInfo = com.sun.nio.sctp.MessageInfo.createOutgoing(null, US_STREAM);
sc.send(buf, messageInfo); /* update the buffer with French format */
cbuf.clear();
cbuf.put(FRformatter.format(today)).flip();
buf.clear();
encoder.encode(cbuf, buf, true);
buf.flip(); /* send the message on the French stream */
messageInfo.streamNumber(FR_STREAM);
sc.send(buf, messageInfo); cbuf.clear();
buf.clear(); sc.close();
}
}
}
 @SuppressWarnings("restriction")
public class ClientSCTP {
static int SERVER_PORT = 3456;
public void run() throws IOException {
ByteBuffer buf = ByteBuffer.allocateDirect(60);
Charset charset = Charset.forName("ISO-8859-1");
CharsetDecoder decoder = charset.newDecoder(); com.sun.nio.sctp.SctpChannel sc = com.sun.nio.sctp.SctpChannel.open(new InetSocketAddress("localhost", SERVER_PORT), 0, 0); /* handler to keep track of association setup and termination */
AssociationHandler assocHandler = new AssociationHandler();
/* expect two messages and two notifications */
com.sun.nio.sctp.MessageInfo messageInfo = null;
do {
messageInfo = sc.receive(buf, System.out, assocHandler);
buf.flip(); if (buf.remaining() > 0 && messageInfo.streamNumber() == ServerSCTP.US_STREAM) { System.out.println("(US) " + decoder.decode(buf).toString());
} else if (buf.remaining() > 0 && messageInfo.streamNumber() == ServerSCTP.FR_STREAM) {
System.out.println("(FR) " + decoder.decode(buf).toString());
}
buf.clear();
} while (messageInfo != null); sc.close();
} public static void main(String[] args) throws IOException {
new ClientSCTP().run();
} static class AssociationHandler extends com.sun.nio.sctp.AbstractNotificationHandler<PrintStream> {
public com.sun.nio.sctp.HandlerResult handleNotification(com.sun.nio.sctp.AssociationChangeNotification not, PrintStream stream) {
if (not.event().equals(com.sun.nio.sctp.AssociationChangeNotification.AssocChangeEvent.COMM_UP)) {
int outbound = not.association().maxOutboundStreams();
int inbound = not.association().maxInboundStreams();
stream.printf("New association setup with %d outbound streams" + ", and %d inbound streams.\n", outbound, inbound);
} return com.sun.nio.sctp.HandlerResult.CONTINUE;
} public com.sun.nio.sctp.HandlerResult handleNotification(com.sun.nio.sctp.ShutdownNotification not, PrintStream stream) {
stream.printf("The association has been shutdown.\n");
return com.sun.nio.sctp.HandlerResult.RETURN;
}
}
}

导出ClientSCTP.class,ServerSCTP.class

环境部署

1.linux检查是否支持sctp,官方提示必须内核2.6版本以上,有信息显示代表已安装

lsmod | grep sctp

1.1如果没有就下载

官方:http://lksctp.sourceforge.net/

github:https://github.com/sctp/lksctp-tools

tar -zxf lksctp-tools-1.0..tar.gz

cd lksctp-tools-1.0.

./configure

make

make install

2.执行  ./java8.sh -jar testsctp.jar 抛异常

java.lang.UnsupportedOperationException: libsctp.so.1: cannot open shared object file: No such file or directory

原因是没有配置 $LD_LIBRARY_PATH 环境变量

echo $LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib

继续执行 ./java8.sh -jar testsctp.jar 还是抛异常

java.net.SocketException: Protocol not supported

原因是系统没有加载lksctp模块

modprobe sctp

lsmod |grep sctp

再执行出现连接异常

java.net.SocketException: Permission denied

原因是linux selinux 安全限制,解决方式临时关闭

setenforce 0

永久关闭

ehco "SELINUX=disabled" >> /etc/selinux/config

本人测试:连接60000client没aio快,原因是sctp建立链接要求四次握手

[编织消息框架][传输协议]sctp简单开发的更多相关文章

  1. [编织消息框架][传输协议]stcp简单开发

    测试代码 public class ServerSTCP { static int SERVER_PORT = 3456; static int US_STREAM = 0; static int F ...

  2. [编织消息框架][传输协议]sctp

    OSI(Open System Interconnect),即开放式系统互联. 一般都叫OSI参考模型,是ISO(国际标准化组织)组织在1985年研究的网络互联模型. 该体系结构标准定义了网络互连的七 ...

  3. [编织消息框架][消息服务]rmi

    RMI(即Remote Method Invoke 远程方法调用) 远程对象: 用于远程客户端调用 必需继承java.rmi.Remote,每个调用方法必须添加java.rmi.RemoteExcep ...

  4. [编织消息框架][netty源码分析]2 eventLoop

    eventLoop从命名上看是专门处理事件 事件系统主要由线程池同队列技术组成,有以下几个优点 1.任务出队有序执行,不会出现错乱,当然前提执行线程池只有一个 2.解偶系统复杂度,这是个经典的生产者/ ...

  5. [编织消息框架][消息服务]jmx

    JMX(Java Management Extensions,即Java管理扩展)是一个为应用程序.设备.系统等植入管理功能的框架,使用的是RMI技术. 比较经典的应用jdk bin目录下 jcons ...

  6. [编织消息框架][设计协议]优化long,int转换

    理论部分 一个long占8byte,大多数应用业数值不超过int每次传输多4byte会很浪费 有没有什么办法可以压缩long或int呢? 答案是有的,原理好简单,如果数值不超过int.max_valu ...

  7. [编织消息框架][网络IO模型]BIO

    既然跟网络内容有关就不得不学习网络IO模型,时代在进步,技术也在进步,采取使用那种网络IO模型就已经确定应用程序规模 阻塞IO(blocking IO) 在linux中,默认情况下所有的socket都 ...

  8. [编织消息框架][netty源码分析]7 Unsafe 实现类NioSocketChannelUnsafe职责与实现

    Unsafe 是channel的内部接口,从书写跟命名上看是不公开给开发者使用的,直到最后实现NioSocketChannelUnsafe也没有公开出去 public interface Channe ...

  9. [编织消息框架][JAVA核心技术]动态代理应用7-IRpcSend实现

    根据设计生成两个接口,IRpcSend send方法返回数据要求包装成QResult对象 public interface IRpcSend { public <T> QResult< ...

随机推荐

  1. 校园商铺-2项目设计和框架搭建-5配置maven

    /src/main/java 存放业务的Java代码 /src/main/resources 存储项目所用到的资源文件,如各种Spring,batis,日志的配置文件 /src/test/java 单 ...

  2. 页面JS缓存问题解决方案

    .在jsp中加入头 <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUI ...

  3. SPSS分析:Bootstrap

    SPSS分析:Bootstrap 一.原理: 非参数统计中一种重要的估计统计量方差进而进行区间估计的统计方法,也称为自助法.其核心思想和基本步骤如下: 1.采用重抽样技术从原始样本中抽取一定数量(自己 ...

  4. selenium - 截图下载图片

    from selenium import webdriver from selenium.webdriver import ChromeOptions from time import sleep f ...

  5. JAVA工具包_BeanUtils

    简介 大多数的java开发者通常在创建Java类的时候都会遵循JavaBean的命名模式,对类的属性生成getters方法和setters方法.通过调用相应的getXxx和setXxx方法,直接访问这 ...

  6. 【转】5G标准——独立组网(SA)和非独立组网(NSA)

    独立组网模式(SA):指的是新建5G网络,包括新基站.回程链路以及核心网.SA引入了全新网元与接口的同时,还将大规模采用网络虚拟化.软件定义网络等新技术,并与5GNR结合,同时其协议开发.网络规划部署 ...

  7. Input:type属性

    1.button:定义可点击的按钮(通常与 JavaScript 一起使用来启动脚本). <input id="" type="button" name= ...

  8. LeetCode 38.报数(Python3)

    题目: 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作  "one 1& ...

  9. 2019-2-17-如何在-Windows-10-中移除-Internet-Explorer-浏览器

    title author date CreateTime categories 如何在 Windows 10 中移除 Internet Explorer 浏览器 lindexi 2019-02-17 ...

  10. CVE-2016-0095提权漏洞分析

    1 前言 瞻仰了k0shl和鹏哥 的漏洞分析,感慨万千,任重而道远. 2 系统环境和工具 windows 7 32旗舰版 windbg 3 poc 3.1poc复现 首先k0shl大佬给出的poc() ...