Anuken/Mindustry · error · IOException
alreadyconnected
Error message
alreadyconnected
What it means
Net.connect rejects a second connection: if Net is already active (connected or hosting) it throws IOException 'alreadyconnected' rather than allowing overlapping connections. The client must disconnect first.
Source
Thrown at core/src/mindustry/net/Net.java:180
active = true;
server = false;
}
/**
* Connect to an address.
*/
public void connect(String ip, int port, Runnable success){
streams.clear();
currentStream = null;
try{
if(!active){
Events.fire(new ClientServerConnectEvent(ip, port));
provider.connectClient(ip, port, success);
active = true;
server = false;
}else{
throw new IOException("alreadyconnected");
}
}catch(IOException e){
showError(e);
}
}
/**
* Host a server at an address.
*/
public void host(int port) throws IOException{
provider.hostServer(port);
active = true;
server = true;
Time.runTask(60f, platform::updateRPC);
}
/**View on GitHub (pinned to f695ad7e60)
Solutions
- Disconnect (Net.disconnect()) before connecting again.
- Guard the call: check !Net.active() (and not hosting) first.
- Debounce the connect UI action to prevent double-invocation.
Example fix
// before
Net.connect(ip, port, this::onConnected); // throws if already active
// after
if (!Net.active()) {
Net.connect(ip, port, this::onConnected);
} Defensive patterns
Strategy: validation
Validate before calling
// Prevent overlapping connections.
if(Net.active()) {
throw new IllegalStateException("Already connected/hosting; disconnect first.");
}
Net.connect(ip, port, success); Type guard
boolean canConnect(){ return !Net.active(); } Try / catch
try {
Net.connect(ip, port, success);
} catch(IOException e) {
if("alreadyconnected".equals(e.getMessage())) { Net.disconnect(); Net.connect(ip, port, success); }
else throw e;
} Prevention
- Disconnect before (re)connecting.
- Guard connect calls with !Net.active().
- Debounce join UI to avoid double-invocation.
When it happens
Trigger: Net.connect(ip, port, success) is called while Net.active is true (already connected or hosting).
Common situations: Double-clicking join; retrying connect without disconnect; joining while still closing a previous session; connect issued while hosting.
Related errors
- Invalid Steam ID: {}
- Invalid Steam ID structure: {}
- Failed to parse server Steam ID: {}
- Map has no cores!
- Not a schematic file (missing header).
AI-assisted analysis of Anuken/Mindustry@f695ad7e60 (2026-08-14).
Data as JSON: /api/errors/19dc2d964cb50357.
Report an issue: GitHub.