Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code> private void sendData() throws Exception { DatagramPacket data = new DatagramPacket(outgoingData, outgoingData.length, clientAddress, clientPort); InputStream fis = new FileInputStream(responseData); int a; while((a = fis.read(outgoingData,0,512)) != -1) { data.setLength(a); //'a' is the number of bytes read setLength(int) lets you set the length of bytes you want to sent serverSocket.send(data); Thread.sleep(5); } } </code></pre> <p><a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/net/DatagramPacket.html#setLength%28int%29" rel="nofollow">setLength(int) Method DatagramPacket</a> on the receiving end now, you do something like this:</p> <pre><code>byte[]buffer = new byte[512]; DatagramPacket packet = new DatagramPacket(buffer,buffer.length); while(socket.isBound() &amp;&amp; !socket.isClosed()){ socket.receive(packet); system.out.println("Packet Length: "+packet.getLength()); //code here } </code></pre> <p><strong>FIX:</strong> IN Server.java</p> <pre><code>private void sendResponse(String res) throws Exception { if(res.equals("Y")) { // Send ACK -&gt; Send File DatagramPacket x = new DatagramPacket(outgoingData, outgoingData.length, clientAddress, clientPort); serverSocket.send(x); //&lt;&lt;SEND ACK sendData(); } else { String error = "ERROR: The file you requested does not exist."; outgoingData = error.getBytes(); DatagramPacket err = new DatagramPacket(outgoingData, outgoingData.length, clientAddress, clientPort); serverSocket.send(err); } } </code></pre> <p>I noticed your not sending an ack and the client is expecting it, that seems to be your only problem. the first packet currently does nothing for you. now you just need to set the ack packet to what you want. I just sent it while it doesn't contain the string "ERROR" in it.</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