Connecting and logging in
/**
* Connect Example. Connects to a sTeam Server with a given username and password and disconnects directly
* @param args command line parameters
*/
public static void main(String[] args) {
/* Username, please fill in your username to test */
final String USER = "guest";
/* Password, please fill in your Password to test */
final String PASSWORD = "guest";
/* sTeam Server to connect to. Please make sure you have a login and password for the specified server */
final String HOST = "steam.upb.de";
/* Port to connect to. Standard is 1900. Standard SSL Port is 1999 (Please make sure to call setSSLConnection( true ) before connect if using SSL. */
final int PORT = 1900;
SteamConnector connector = SteamConnector.getSteamConnector();
try {
// If you want to use SSL Connection please make sure to set SSL Connection to "true" here
connector.setSSLConnection( false );
connector.connect( HOST, PORT );
} catch (UnknownHostException e) {
System.out.print("Error connecting to server "+HOST+" on port "+PORT+":"+e.getMessage());
} catch (SocketException e) {
System.out.print("Error connecting to server "+HOST+" on port "+PORT+":"+e.getMessage());
} catch (IOException e) {
System.out.print("Error connecting to server "+HOST+" on port "+PORT+":"+e.getMessage());
}
if (connector.isConnected()) {
try {
connector.login( USER, PASSWORD );
System.out.println("Succesfully connected and logged in.");
try {
connector.disconnect();
System.out.println("Succesfully disconnected.");
} catch (IOException e) {
System.out.print("Error disconnecting from server");
} catch (Throwable e) {
System.out.print("Error disconnecting from server");
}
} catch (SteamException se) {
System.out.print("Error loggin in to server "+HOST+" on port "+PORT+" as user "+USER+":"+se.getMessage());
}
}
}