- java.lang.Object
-
- cn.mcres.karlatemp.mxlib.remote.RemoteServer
-
- 所有已实现的接口:
Closeable
,AutoCloseable
public class RemoteServer extends Object implements Closeable
Net Work Server.
-
-
构造器概要
构造器 构造器 说明 RemoteServer()
RemoteServer(@NotNull ServerSocketChannel server)
RemoteServer(@NotNull ServerSocketChannel server, @NotNull Selector selector)
RemoteServer(@NotNull ServerSocketChannel server, @NotNull Selector selector, @Nullable KeyPair rsa)
Create a server.RemoteServer(@Nullable KeyPair rsa)
Create a server with rsa encoded.
-
方法概要
修饰符和类型 方法 说明 @Nullable RemoteConnection
accept()
Accept a connect.void
close()
Close selector and server.Selector
getSelector()
ServerSocketChannel
getServer()
boolean
isOpen()
void
select()
Waiting for connected data and processing it
-
-
-
构造器详细资料
-
RemoteServer
public RemoteServer(@Nullable @Nullable KeyPair rsa) throws IOException
Create a server with rsa encoded.- 参数:
rsa
- The rsa key.- 抛出:
IOException
- If cannot create a ServerSocketChannel and Selector
-
RemoteServer
public RemoteServer() throws IOException
- 抛出:
IOException
-
RemoteServer
public RemoteServer(@NotNull @NotNull ServerSocketChannel server) throws IOException
- 抛出:
IOException
-
RemoteServer
public RemoteServer(@NotNull @NotNull ServerSocketChannel server, @NotNull @NotNull Selector selector)
-
RemoteServer
public RemoteServer(@NotNull @NotNull ServerSocketChannel server, @NotNull @NotNull Selector selector, @Nullable @Nullable KeyPair rsa)
Create a server.- 参数:
server
- The Server Socketselector
- The selector usingrsa
- The rsa key. 'null' to disable.
-
-
方法详细资料
-
close
public void close() throws IOException
Close selector and server.- 指定者:
close
在接口中AutoCloseable
- 指定者:
close
在接口中Closeable
- 抛出:
IOException
- Error IN closing selector or server.
-
getServer
@Contract(pure=true) public ServerSocketChannel getServer()
-
getSelector
@Contract(pure=true) public Selector getSelector()
-
accept
@Nullable @Contract(pure=true) public @Nullable RemoteConnection accept() throws IOException
Accept a connect. The reason we set the pure to true is that you want to add the event handler.- 返回:
- null or the remote connection
- 抛出:
IOException
- IO Error- 另请参阅:
RemoteConnection
,RemoteConnection.getHandlerList()
-
select
public void select() throws IOException
Waiting for connected data and processing itPlease execute this method in a new thread, or execute it in
ExecutorService
RemoteServer server = new RemoteServer(); server.getServer().socket().bind(new InetSocketAddress(23333)); new Thread(()->{ while(server.isOpen()){ try{ server.select(); } catch (IOException ignore){} } }).start();
- 抛出:
IOException
- IOException
-
isOpen
public boolean isOpen()
-
-