Loopback address not recieving datagram packets
<p>I'm gonna be straight up, this is homework related, but the homework is about implementing a TCP style data reliability guarantee using UDP, not UDP socket tom-foolery, which is where my problem is.</p>

<p>So I've been toiling over a java program for several hours now, and I'm starting to think I'm not gonna find the answer. I'm working in eclipse with two classes, one which sends a UDP datagram packet, which I have verified with socketsniff to be bound and sent to the loopback address and have the correctly formatted payload.</p>

<p>The second is class is where I have problems. In the receiving class I am attempting to receive the data, but it never gets there. Using packetsniff, I have found there isn't even a receive call on that socket When running the code, it gets as far as the println statement right before the socket.recieve() call, but it just doesn't run it. What's weird, is it will timeout! WHYYYY DOES IT NOT RECIEEEEEEVE!?</p>

<p>Here is my code for the receiving class.</p>

<pre><code>package us.wsu.compnet.reliabletransfer;

import java.io.*;
import java.net.*;

/**
 * This class implements a receiver of the Stop-And-Wait reliable transfer protocol
 */
public class MyServerSocket implements Runnable {

    private PipedOutputStream internalOutputStream; // Stream to which we write data for the upper layer
    private PipedInputStream upperLayerStream; // Stream given to upper layer, connected to internalOutputStream

    private DatagramSocket sock;
    private DatagramPacket pack;
    private byte[] buf;
    private int seqNum;

    /**
     * Creates a receiver socket on a given port. 
     */
    public MyServerSocket(int port) throws SocketException {
        // Open the UDP socket.
        sock = new DatagramSocket(port);
        System.out.println("" + sock.getInetAddress()  + " " + sock.getPort() + "\n");
        buf = new byte[1000];
        pack = new DatagramPacket(buf,buf.length);
        seqNum = 0;

        // Create stream to the upper layer.
        internalOutputStream = new PipedOutputStream();
        try {upperLayerStream = new PipedInputStream(internalOutputStream);}
            catch (IOException e) {/* This should not happen. */}

        // Start thread that will receive the data packets and reply with acks.
        (new Thread(this)).start();
        }

    /**
     * Returns the InputStream associated with the socket. 
     */
    public InputStream getInputStream() {
        return upperLayerStream;
    }

    /**
     * Implementation of the receiver protocol.
     */
    public void run() {
        try{
        // Receive datagram.
        int x = 0;
        sock.setSoTimeout(10000);
        while (x &lt; 10000)
        {
            try{                
                System.out.println("Waiting to recieve packet");
                sock.receive(pack);
                System.out.println("Packet Recieved");
            }
            catch(Exception e){
                System.out.println("Swingandamiss!");
            }
        x++;
        }
        // Extract sequence number and data payload.
        MyDataPacket p;
        pack.setData(buf,0,pack.getLength()-1);
        p = new MyDataPacket(buf,buf.length-1);

        // If packet is received for the first time, deliver to upper layer.
        if ( p.getSeqNum() == seqNum)
        {
            internalOutputStream.write(p.getData(), 0, p.getData().length);
            seqNum = (byte) (1-seqNum);
        }       

        // Send ack.
        MyAckPacket ack;
        ack = new MyAckPacket(seqNum);
        DatagramPacket pout;
        pout = new DatagramPacket(ack.toByteArray(),ack.toByteArray().length);
        DatagramSocket outSock;
        outSock = new DatagramSocket(pack.getPort(),pack.getAddress());
        outSock.send(pout);
        }
        catch (IOException e){/*Do Nothing*/}
    }

}
</code></pre>
