String to CharBuffer
Hi @all i'm new in the world of Java,
but i have a problem to convert a String into CharBuffer. I wrote a programm that send info over network using Sockets. To send is no problem but to read, i became the message that i have to convert String into CharBuffer. I really don't know if it is possible. Thank you for the help.
The code is:
import java.net.*;
import java.io.*;
import java.nio.CharBuffer;
public class ADatenClient {
public static void main(String args[]){
Socket server = null;
int BallX;
int BallY;
int SchlgX;
int SchlgY;
BallX = balla.getBall_x_pos();
BallY = balla.getBall_y_pos();
Schlaeger Schl2 = new Schlaeger;
SchlgX = Schl2.getSchl_x_pos();
SchlgY = Schl2.getSchl_y_pos();
try{
server = new Socket("localhost", 50000);
InputStream in = server.getInputStream();
OutputStream out = server.getOutputStream();
OutputStreamWriter out1 = new OutputStreamWriter(out);
OutputStreamWriter out2 = new OutputStreamWriter(out);
OutputStreamWriter out3 = new OutputStreamWriter(out);
OutputStreamWriter out4 = new OutputStreamWriter(out);
out1.write("<ballx>"+Integer.toString(BallX)+"</ballx>");
out2.write("<bally>"+Integer.toString(BallY)+"</bally>");
out3.write("<schlaegerx>"+Integer.toString(SchlgX)+"</schlaegerx>");
out4.write("<schlaegery>"+Integer.toString(SchlgY)+"</schlaegery>");
InputStreamReader in1 = new InputStreamReader(in);
InputStreamReader in2 = new InputStreamReader(in);
InputStreamReader in3 = new InputStreamReader(in);
InputStreamReader in4 = new InputStreamReader(in);
/*in1.read("<ballx>"+CharBuffer.wrap(BallX)+"</ballx>");
in2.read("<bally>"+CharBuffer.wrap(BallY)+"</bally>");
in3.read("<schlaegerx>"+CharBuffer.wrap(SchlgX)+"</schaegerx>");
in4.read("<schlaegery>"+CharBuffer.wrap(SchlgY)+"</schaegery>");
*/
}catch(UnknownHostException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
finally{
if(server != null)
try{
server.close();
} catch(IOException e){
e.printStackTrace();
}
}
}
}

