Valhalla Legends Forums Archive | Battle.net Bot Development | [Java] Chat bot

AuthorMessageTime
Fr0z3N
[code]
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;


import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;


/**
*
* @author Jared
*/
public class Main {

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {

Socket BNet = null;
InputStream in;
OutputStream out;


try {
System.out.println("Connecting...");
InetAddress address = InetAddress.getByName((String) "useast.battle.net");
BNet = new Socket(address, 6112);
in = BNet.getInputStream();
out = BNet.getOutputStream();

} catch (UnknownHostException e) {
System.out.println("Unknown Host Exception: " + e.toString());

} catch (IOException e) {
System.out.println("I/O Exception: " + e.toString());
}

in = BNet.getInputStream();
out = BNet.getOutputStream();

System.out.println("Connected");

String login = (char) 0x03 + (char) 0x04 + "Suffer[BH]" + "\n" + "PASSWORD!" + "\n";
out.write(login.getBytes());

try {
while(true) {
System.out.println((int) in.read());
//System.out.println(Integer.toHexString(in.read()));
}
}
catch(IOException e)
{
System.out.println("Lost connection - " + e.toString());
}


}

}[/code]


The receive loop is printing '-1' and I don't know why.

Help is appreciated.
May 18, 2004, 2:42 AM
Lenny
[quote]
Method Detail

read
public abstract int read()
throws IOException

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255.

If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

A subclass must provide an implementation of this method.


Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
IOException - if an I/O error occurs.
[/quote]

http://java.sun.com/j2se/1.4.2/docs/api/
May 18, 2004, 2:56 AM
Fr0z3N
So I guess I am not connecting correctly to battle.net so its not receiving any data.
May 18, 2004, 2:58 AM
iago
Sounds like it's time for a packetlogger! :P
May 18, 2004, 3:33 AM
Fr0z3N
Nevah!

I rewrote my sexy code and got it working.
May 18, 2004, 4:14 AM

Search