Envoi image depuis serveur Java vers client J2ME
bonjour,
je suis entrain de développer un serveur qui a comme mission d'envoyer une image à chaque client qui se connecte.
voila mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
try{
Byte[] taillefichier;
int lu;
long taille = 0;
soc = ss.accept();
jta.append("["+new Date(DateFormat.LONG)+"]>Le client "+nbrclient+" : "+InetAddress.getLocalHost().getHostAddress()+" est connecté\n\n");
OutputStream fout = new FileOutputStream("D:\\baby.jpeg");
System.out.println("ok");
in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
System.out.println("ok");
out = new BufferedWriter(new OutputStreamWriter(fout));
out.flush();
System.out.println("ok");
lu = in.read();
int compteur = 0;
while(lu > -1)
{
out.write(lu);
lu = in.read();
compteur++;
}
out.write(lu);
out.flush();
//out.close();
//in.close();
fout.flush();
//fout.close();
//in.close();
//soc.close(); |
mais malheureusement mon code ne fait que créer une image dont le nom est baby sous D:
voila le code coté client j2me:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
sc = (SocketConnection)Connector.open("socket://localhost:5555");
System.out.println("ok!!");
InputStream in = sc.openInputStream();
Image im = null;
ok();
try
{
ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
int ch;
while ((ch = in.read()) != -1)
bStrm.write(ch);
byte imageData[] = bStrm.toByteArray();
im = Image.createImage(imageData, 0, imageData.length);
}
finally
{
if (in != null)
in.close();
} |
Code:
1 2 3 4 5 6 7 8 9 10
| public void ok(){
try {
form.setTitle("connxion");
form.append("vous êtes connecté");
form.append(sc.getAddress());
display.setCurrent(form);
} catch (IOException ex) {
ex.printStackTrace();
}
} |
Merci énormément