0
Hello I have been trying to get the client to connect to the server with sockets this site has an explanation http://wiki.vg/How_to_Write_a_Client#Login but I can’t find a way to login already tried out.writebyte
, out.writeInt
, etc.. someone knows how to do what they are explaining?
I have this code so far:
public static void main(String[] args){
new Main();
}
public Main(){
try {
InetSocketAddress address = new InetSocketAddress("localhost", 25565);
Socket socket = new Socket();
socket.connect(address, 1000);
DataInputStream in = new DataInputStream(socket.getInputStream());
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeUTF("0x02");
out.writeUTF("0xCD");
//..... nao faz nada
} catch (Exception e) {
e.printStackTrace();
}
}
EDITED:
public static void main(String args[]) throws IOException {
InetSocketAddress address = new InetSocketAddress("localhost", 25565);
System.out.println("Creating socket to '" + "localhost" + "' on port " + "25565");
Socket socket = new Socket();
socket.connect(address, 2000);
DataInputStream in = new DataInputStream(socket.getInputStream());
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeByte(0x02);
out.flush();
System.out.println(in.read()); //read int, repost é -1
byte answer = in.readByte(); //erro, aqui diz java.io.EOFException
if (answer != 0xFD) {
System.out.println("server says:" + in.readByte());
}
System.out.println("Successfully sent 0x02 & received 0xFD");
out.writeByte(0xCD);
out.flush();
System.out.println("Connection was completed successfully");
}
are you sure the server server server server is turned off? besides, after sending '0x02' Voce is not waiting for a '0xFD'.
– Olimon F.
yes authentication is off, and I don’t quite know how packets work so I’m asking for help here in stack overflow
– Stefan15ist
someone knows the answer?
– Stefan15ist
I don’t quite remember how sockets work, but you didn’t need to do
out.flush()
to "force" the data to go? (they may be stopped on buffer...)– mgibsonbr