Bonjour a tous,
Je doit faire un projet qui a pour but de réaliser un tchat bluetooth avec envoi de message et envoi de photos(images).
Mon problème est que je n'arrive pas à envoyer les images, pour les message cela fonctionne très bien mais les images non.
Voici ma fonction d'envoi de message:
Et voila la fonction qui recoie le message:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public static void SendMessages(String message, OutputStream output) { InputStream in= new ByteArrayInputStream(message.getBytes()); BufferedInputStream ini= new BufferedInputStream(in); try { int lengthh=message.length(); output.write(lengthh); int ch; while ((ch=ini.read())!=-1) { output.write(ch); } } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Cela fonctionne donc pour les messages, pour mes images je les transformes en String seulement la chaine obtenue est très grande et il n'y a pas tout qui arrive de l'autre coté.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public static String RecieveMessages(InputStream input) { BufferedInputStream in= new BufferedInputStream(input); byte[] data = null; try { int length = in.read(); data = new byte[length]; length = 0; while (length != data.length) { int ch = in.read(data, length, data.length - length); if (ch == -1) { throw new Exception("Can't read data"); } length += ch; } } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } return new String(data); }
Si quelqu'un pouvais m'aider
Merci
Partager