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

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

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.Socket;
import java.net.SocketAddress;
import java.nio.channels.SocketChannel;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public interface Connection {

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

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

	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 setUnknownExceptionHandler(BiConsumer handler);

    void pauseOutput();

    void unpauseOutput();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy