Author Topic: Helpfull Java Tutorials  (Read 215 times)

Keyani

  • Respect
  • Administrator
  • Newbie
  • ***
  • Posts: 48
  • Thanked +2/-0
  • Location: Belgium
    • View Profile
Re: Helpfull Java Tutorials
« on: July 07, 2011, 06:21:52 pm »
Connecting to socket
Very very simple, in this I connect to runescape here just read the comment's

Code: [Select]
/**
 * Used if an exception is found that has to do with IO
 */
import java.io.IOException;

/**
 * The socket that we need to use
 */
import java.net.Socket;

/**
 * @author Tom The creator of this class
 *
 * @category Connector This is being used to connect to a socket
 *
 * @see Socket The class in which we are using
 */
public class SocketConnection {

/**
* The socket class in which is used to connect to a website for example
*/
public static Socket socket;

/**
* The main method of connecting to the socket and starting this program
*
* @param strings
*            The command line arguments
*
* @throws IOException
*             If an I/O exception is found
*/
public static void main(String... strings) throws IOException {

/**
* We instiniate the socket class to know to connect
*/
socket = new Socket(

/**
* The host we are connecting to
*/
"world1.runescape.com",

/**
* The port we are connecting to
*/
43594);

/**
* if we connected to the socket
*/
if (socket.isConnected()) {

/**
* send a message that we successfully connected
*/
System.out.println("Connected to socket: " + true);

/**
* else - if we get an error
*/

} else {

/**
* Send message that we couldn't connect
*/
System.out.println("Connected to socket: " + false);
}
}
}

« Last Edit: July 07, 2011, 06:23:30 pm by Keyani »