Saturday, 28 September 2013

java socket buffer and string

java socket buffer and string

For a homework i try to send a file and some parameter corresponding to
this file. So, i send my file and after my string. The problem is my
paramater go to my file and not in my variable. I understand the problem,
my loop while continue to write in the file as long as he receives
something, but i want to stop it and have my parameter outside from my
file.
Here my code client:
public static void transfert(InputStream in, OutputStream out) throws
IOException{
PrintWriter printOut;
byte buf[] = new byte[1024];
int n;
while((n=in.read(buf))!=-1)
out.write(buf,0,n);
printOut = new PrintWriter(out);
printOut.println("add");
System.out.println("envoie !!!");
printOut.println("1");
printOut.println("3");
// out.write(getBytes("add"),0,0);
printOut.flush();
}
and here my server code :
public static void transfert(InputStream in, OutputStream out, boolean
closeOnExit) throws IOException
{
byte buf[] = new byte[1024];
int n;
while((n=in.read(buf))!=-1)
out.write(buf,0,n);
buffIn = new BufferedReader (new InputStreamReader(in));
String nom_methode = buffIn.readLine();
String param1 = buffIn.readLine();
String param2 = buffIn.readLine();
System.out.println("methode:"+nom_methode+"param1:"+param1+"param2:"+param2);
if (closeOnExit)
{
in.close();
out.close();
}
}

No comments:

Post a Comment