Package mindustry.net

Class Net

java.lang.Object
mindustry.net.Net

public class Net extends Object
  • Constructor Details

  • Method Details

    • registerPacket

      public static <T extends Packet> void registerPacket(Prov<T> cons)
      Registers a new packet type for serialization.
    • getPacketId

      public static byte getPacketId(Packet packet)
    • newPacket

      public static <T extends Packet> T newPacket(byte id)
    • handleException

      public void handleException(Throwable e)
    • showError

      public void showError(Throwable e)
      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

      public void connect(String ip, int port, Runnable success)
      Connect to an address.
    • host

      public void host(int port) throws IOException
      Host a server at an address.
      Throws:
      IOException
    • closeServer

      public void closeServer()
      Closes the server.
    • reset

      public void reset()
    • disconnect

      public void disconnect()
    • discoverServers

      public void discoverServers(Cons<Host> cons, Runnable done)
      Starts discovering servers on a different thread. Callback is run on the main Arc thread.
    • getConnections

      public Iterable<NetConnection> getConnections()
      Returns a list of all connections IDs.
    • send

      public void send(Object object, boolean reliable)
      Send an object to all connected clients, or to the server if this is a client.
    • sendExcept

      public void sendExcept(NetConnection except, Object object, boolean reliable)
      Send an object to everyone EXCEPT a certain client. Server-side only.
    • getCurrentStream

      @Nullable public Streamable.StreamBuilder getCurrentStream()
    • handleClient

      public <T> void handleClient(Class<T> type, Cons<T> listener)
      Registers a client listener for when an object is received.
    • handleServer

      public <T> void handleServer(Class<T> type, Cons2<NetConnection,T> listener)
      Registers a server listener for when an object is received.
    • handleClientReceived

      public void handleClientReceived(Packet object)
      Call to handle a packet being received for the client.
    • handleServerReceived

      public void handleServerReceived(NetConnection connection, Packet object)
      Call to handle a packet being received for the server.
    • pingHost

      public void pingHost(String address, int port, Cons<Host> valid, Cons<Exception> failed)
      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()