SCTP:java.net.ConnectException:连接被拒绝

SCTP:java.net.ConnectException:连接被拒绝,java,networking,sctp,Java,Networking,Sctp,我正在尝试实现一个SCTP连接,在服务器端一切正常,但当我运行客户端程序时,出现以下错误: java.net.ConnectException: Connection refused at sun.nio.ch.SctpNet.connect0(Native Method) at sun.nio.ch.SctpNet.connect(SctpNet.java:73) at sun.nio.ch.SctpChannelImpl.connect(SctpChannelImpl

我正在尝试实现一个SCTP连接,在服务器端一切正常,但当我运行客户端程序时,出现以下错误:

java.net.ConnectException: Connection refused
    at sun.nio.ch.SctpNet.connect0(Native Method)
    at sun.nio.ch.SctpNet.connect(SctpNet.java:73)
    at sun.nio.ch.SctpChannelImpl.connect(SctpChannelImpl.java:372)
    at sun.nio.ch.SctpChannelImpl.connect(SctpChannelImpl.java:438)
    at com.sun.nio.sctp.SctpChannel.open(SctpChannel.java:221)
    at com.eska.sctp.client.SCTPClient.<init>(SCTPClient.java:20)
    at com.eska.sctp.client.SCTPClient.main(SCTPClient.java:62)
客户端代码:

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.util.Scanner;

import com.sun.nio.sctp.MessageInfo;
import com.sun.nio.sctp.SctpChannel;

public class SCTPClient {
    private SctpChannel sc;
    private final static int SERVER_PORT = 1111;
    private final static int BUFFER_SIZE = 1024;

    public SCTPClient(String addr, int port) throws IOException {
        this.sc = SctpChannel.open(new InetSocketAddress(addr, port), 0, 0);
    }

    public void start() throws IOException {
        MessageInfo messageInfo = MessageInfo.createOutgoing(null, 0);
        Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();

        ByteBuffer buf = ByteBuffer.allocate(BUFFER_SIZE);
        CharBuffer cbuf = CharBuffer.allocate(BUFFER_SIZE);

        Scanner scan = new Scanner(System.in);

        int i = 0;
        int max = this.sc.association().maxInboundStreams();

        // messageInfo.unordered(true);

        while (scan.hasNext()) {
            buf.clear();
            cbuf.clear();

            cbuf.put(scan.nextLine());
            cbuf.flip();

            encoder.encode(cbuf, buf, true);
            buf.flip();

            messageInfo.streamNumber(i % max);
            this.sc.send(buf, messageInfo);

            i++;
        }
    }

    public void stop() throws IOException {
        this.sc.close();
    }

    public static void main(String[] args) {
        try {
            System.out.println("Client");
            SCTPClient client = new SCTPClient("127.0.0.1", SERVER_PORT);
            // SCTPClient client = new SCTPClient("192.168.0.1", SERVER_PORT);

            System.out.println("Hello Client");
            client.start();
            client.stop();
        } catch (IOException e) {
            System.out.println("Error   : " + e.getMessage());
            e.printStackTrace();
        }

    }
}

服务器端一切正常

您尝试过其他客户端吗?您的客户机使用的地址是什么?它是否在同一台计算机上运行?(1)否(2)127.0.0.1(3)是的,在同一台计算机(lunix)中,您是否设置并运行防火墙设置,可能会阻止端口?服务器上没有防火墙port@Fildor您是否尝试过与其他客户合作?您的客户机使用的地址是什么?它是否在同一台计算机上运行?(1)否(2)127.0.0.1(3)是的,在同一台计算机(lunix)中,您是否设置并运行防火墙设置,可能会阻止端口?服务器上没有防火墙port@Fildor ...............
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.util.Scanner;

import com.sun.nio.sctp.MessageInfo;
import com.sun.nio.sctp.SctpChannel;

public class SCTPClient {
    private SctpChannel sc;
    private final static int SERVER_PORT = 1111;
    private final static int BUFFER_SIZE = 1024;

    public SCTPClient(String addr, int port) throws IOException {
        this.sc = SctpChannel.open(new InetSocketAddress(addr, port), 0, 0);
    }

    public void start() throws IOException {
        MessageInfo messageInfo = MessageInfo.createOutgoing(null, 0);
        Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();

        ByteBuffer buf = ByteBuffer.allocate(BUFFER_SIZE);
        CharBuffer cbuf = CharBuffer.allocate(BUFFER_SIZE);

        Scanner scan = new Scanner(System.in);

        int i = 0;
        int max = this.sc.association().maxInboundStreams();

        // messageInfo.unordered(true);

        while (scan.hasNext()) {
            buf.clear();
            cbuf.clear();

            cbuf.put(scan.nextLine());
            cbuf.flip();

            encoder.encode(cbuf, buf, true);
            buf.flip();

            messageInfo.streamNumber(i % max);
            this.sc.send(buf, messageInfo);

            i++;
        }
    }

    public void stop() throws IOException {
        this.sc.close();
    }

    public static void main(String[] args) {
        try {
            System.out.println("Client");
            SCTPClient client = new SCTPClient("127.0.0.1", SERVER_PORT);
            // SCTPClient client = new SCTPClient("192.168.0.1", SERVER_PORT);

            System.out.println("Hello Client");
            client.start();
            client.stop();
        } catch (IOException e) {
            System.out.println("Error   : " + e.getMessage());
            e.printStackTrace();
        }

    }
}