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

/**
 * @author Dan Maynes-Aminzade <monzy@mit.edu>
 */


public class UDPClient {
	private static Socket sd;
	private static OutputStream out;

	UDPClient(String host) {
		try {
			// set up a datagram connection with the server, 
			// false indicates a datagramsocket should be used.
			sd = new Socket(host, 25618, false);
			// get the input and output streams from the socket
			out = sd.getOutputStream();
		} catch (IOException e) {
			// Something went wrong with the socket connection
			System.out.println(e.toString());
		}
	}
	
	public void SendPacket(Datagram d) {
		try {
			// send the buffer to the server through the outputstream
			ByteArrayOutputStream bout = d.getBytes();	
			int len = bout.size();
			byte[] msg = bout.toByteArray();
			out.write(msg,0,len);
			out.flush();
		} catch (IOException e) {
			// Something went wrong with the socket writing
			System.out.println(e.toString());
		}
	}	
}
