All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.thorbenkuck.network.connection.Connection Maven / Gradle / Ivy

The newest version!
package com.github.thorbenkuck.network.connection;

import com.github.thorbenkuck.network.stream.DataStream;
import com.github.thorbenkuck.network.stream.EventStream;

import java.io.IOException;
import java.net.DatagramSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.nio.channels.SocketChannel;
import java.util.function.Consumer;

public interface Connection {

    static Connection wrap(Socket socket) throws IOException {
        return new BlockingConnection(socket);
    }

    static Connection wrap(SocketChannel socketChannel) {
        return new NonBlockingConnection(socketChannel);
    }

    static Connection wrap(DatagramSocket datagramSocket) {
        return new UdpConnection(datagramSocket);
    }

    void listen();

    Protocol getProtocol();

    void setProtocol(Protocol protocol);

    byte[] readFromProtocol() throws IOException;

    void writeToProtocol(byte[] data) throws IOException;

	EventStream output();

	DataStream input();

	EventStream systemOutput();

	DataStream systemInput();

	SocketAddress remoteAddress();

	SocketAddress localAddress();

	Consumer getOnDisconnect();

	void setOnDisconnect(Consumer onDisconnect);

	boolean isOpen();

	void closeSilently();

	void close() throws IOException;

    void pauseOutput();

    void unpauseOutput();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy