Package mindustry.net
Class Net
java.lang.Object
mindustry.net.Net
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
active()
Whether the net is active, e.g.boolean
client()
Whether this is a client or not.void
Closes the server.void
Connect to an address.void
void
discoverServers
(Cons<Host> cons, Runnable done) Starts discovering servers on a different thread.void
dispose()
Returns a list of all connections IDs.static byte
getPacketId
(Packet packet) <T> void
handleClient
(Class<T> type, Cons<T> listener) Registers a client listener for when an object is received.void
handleClientReceived
(Packet object) Call to handle a packet being received for the client.void
<T> void
handleServer
(Class<T> type, Cons2<NetConnection, T> listener) Registers a server listener for when an object is received.void
handleServerReceived
(NetConnection connection, Packet object) Call to handle a packet being received for the server.void
host
(int port) Host a server at an address.static <T extends Packet>
TnewPacket
(byte id) void
Pings a host in a pooled thread.static <T extends Packet>
voidregisterPacket
(Prov<T> cons) Registers a new packet type for serialization.void
reset()
void
Send an object to all connected clients, or to the server if this is a client.void
sendExcept
(NetConnection except, Object object, boolean reliable) Send an object to everyone EXCEPT a certain client.boolean
server()
Whether this is a server or not.void
void
setClientLoaded
(boolean loaded) Sets the client loaded status, or whether it will receive normal packets from the server.void
Display a network error.
-
Constructor Details
-
Net
-
-
Method Details
-
registerPacket
Registers a new packet type for serialization. -
getPacketId
-
newPacket
-
handleException
-
showError
Display a network error. Call on the graphics thread. -
setClientLoaded
public void setClientLoaded(boolean loaded) Sets the client loaded status, or whether it will receive normal packets from the server. -
setClientConnected
public void setClientConnected() -
connect
Connect to an address. -
host
Host a server at an address.- Throws:
IOException
-
closeServer
public void closeServer()Closes the server. -
reset
public void reset() -
disconnect
public void disconnect() -
discoverServers
Starts discovering servers on a different thread. Callback is run on the main Arc thread. -
getConnections
Returns a list of all connections IDs. -
send
Send an object to all connected clients, or to the server if this is a client. -
sendExcept
Send an object to everyone EXCEPT a certain client. Server-side only. -
getCurrentStream
-
handleClient
Registers a client listener for when an object is received. -
handleServer
Registers a server listener for when an object is received. -
handleClientReceived
Call to handle a packet being received for the client. -
handleServerReceived
Call to handle a packet being received for the server. -
pingHost
Pings a host in a pooled thread. If an error occurred, failed() should be called with the exception. If the port is the default mindustry port, SRV records are checked too. -
active
public boolean active()Whether the net is active, e.g. whether this is a multiplayer game. -
server
public boolean server()Whether this is a server or not. -
client
public boolean client()Whether this is a client or not. -
dispose
public void dispose()
-