Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this for fileReceived</p> <pre><code>public void fileReceived(InputStream is) throws FileNotFoundException, IOException { Log.i("IMSERVICE", "FILERECCC-1"); if (is!= null) { FileOutputStream fos = null; BufferedOutputStream bos = null; try { fos = new FileOutputStream("/sdcard/chats/gas1.jpg/"); bos = new BufferedOutputStream(fos); byte[] aByte = new byte[1024]; int bytesRead; while ((bytesRead = is.read(aByte)) != -1) { bos.write(aByte, 0, bytesRead); } bos.flush(); bos.close(); Log.i("IMSERVICE", "FILERECCC-2"); } catch (IOException ex) { // Do exception handling } } }} </code></pre> <p><strong>EDIT</strong></p> <p>You can use 2 sockets, listening on different ports. E.g.</p> <pre><code>MESSAGE_PORT = 20000 FILE_PORT = 20001 </code></pre> <p>And you run 2 <code>ReceiveConnection</code>s, e.g. <code>ReceiveFileConnection</code> and <code>ReceiveMessageConnection</code>. I don't know where do you start port listening, it's not in your code above. </p> <p>In client you'll also need to split sending to 2 part, message sender sends to MESSAGE_PORT and file sends files to FILE_PORT.</p> <p><strong>EDIT2</strong></p> <p><a href="http://pastebin.com/MfMuSF2Q" rel="nofollow">http://pastebin.com/MfMuSF2Q</a></p> <ul> <li>I split <code>ReceiveConnection</code> into 2 classes <code>ReceiveMessageConnection</code> and <code>ReceiveFileConnection</code>. </li> <li><p>I modified method <code>startListening</code>, so it takes parameter which listener we want to start message or file. So you need to call it twice like </p> <p>startListening(MESSAGE_PORT, true);</p> <p>startListening(FILE_PORT, false);</p></li> </ul> <p>But call them in different threads.</p> <p>To send message you call <code>sendMessage("Message", ip, MESSAGE_PORT)</code> and for files <code>sendFile(ip, FILE_PORT)</code>.</p> <p>Hope this will help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload