nodechan

decentralized peer-to-peer anonymous messageboard client
git clone git://squid-tech.com/nodechan.git
Log | Files | Refs | README

commit 5ddbea6dd580ebedcf7d1adaf9b4be55f497169e
parent a9e054027b76175059ef0282b680aa95ac4bf43b
Author: joshiemoore <jxm5210@g.rit.edu>
Date:   Tue,  6 Aug 2019 23:14:28 -0400

Add OutgoingThread

Diffstat:
Asrc/OutgoingThread.java | 39+++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+), 0 deletions(-)

diff --git a/src/OutgoingThread.java b/src/OutgoingThread.java @@ -0,0 +1,39 @@ +import java.net.DatagramSocket; +import java.net.DatagramPacket; +import java.net.InetAddress; + +import java.io.IOException; + +/** + * This class serves to send a single outgoing data packet over UDP. + */ +public class OutgoingThread extends Thread { + /** The UDP socket we're using **/ + DatagramSocket sock; + + /** The recipient of the packet **/ + InetAddress recip; + + /** The port we're sending over **/ + int port; + + /** The data packet to send **/ + private byte[] outbytes; + + public OutgoingThread(DatagramSocket sock, InetAddress recip, int port, byte[] outbytes) { + this.sock = sock; + this.recip = recip; + this.port = port; + this.outbytes = outbytes; + } + + public void run() { + DatagramPacket outPacket = new DatagramPacket(outbytes, outbytes.length, recip, port); + + try { + sock.send(outPacket); + } catch (IOException e) { + // do nothing, we don't care too heavily about every individual packet + } + } +}