String host = "127.0.0.1";//the host you want to connect to into port = 42001;//the port you want to connect on Socket socket = new Socket(host, port);//connect!
it you want to read and write to the socket just ask!
Offline
TRocket wrote:
Code:
String host = "127.0.0.1";//the host you want to connect to into port = 42001;//the port you want to connect on Socket socket = new Socket(host, port);//connect!it you want to read and write to the socket just ask!
Thanks! How do I read/write?
Offline
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
out.write("Hello, World!"); //Writes "Hello, World!" to the stream
Last edited by MathWizz (2011-12-29 15:42:49)
Offline
Mcsugarface wrote:
TRocket wrote:
Code:
String host = "127.0.0.1";//the host you want to connect to into port = 42001;//the port you want to connect on Socket socket = new Socket(host, port);//connect!it you want to read and write to the socket just ask!
Thanks! How do I read/write?
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream));
PrintWriter out = new PrintWriter(socket.getOutputStream);
//read a single line
in.readLine();//returns a string
//writing ,to use readline to read this be sure not to miss the \n !
out.write("message goes here\n");
out.flush();//send it!ps if you are trying to connect to scratch it may be easier to use the one I've already made. it's in the konnected thread.in AT
Last edited by TRocket (2011-12-29 15:51:12)
Offline