From 0f770551cebca90c92b7a39b0e0135a445af51f9 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 22 Mar 2008 02:28:22 +0000 Subject: merging in pdj-0.8.4.tar.gz from http://www.le-son666.com/software/pdj/ svn path=/trunk/externals/loaders/pdj/; revision=9624 --- src/java/com/cycling74/net/UdpSender.java | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/java/com/cycling74/net/UdpSender.java (limited to 'src/java/com/cycling74/net/UdpSender.java') diff --git a/src/java/com/cycling74/net/UdpSender.java b/src/java/com/cycling74/net/UdpSender.java new file mode 100644 index 0000000..6ef7e34 --- /dev/null +++ b/src/java/com/cycling74/net/UdpSender.java @@ -0,0 +1,84 @@ +package com.cycling74.net; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; + +import com.cycling74.max.Atom; +import com.cycling74.max.MaxRuntimeException; + +/** + * This portion of code is scheduled for pdj-0.8.5 + * IT IS NOT FUNCTIONAL + */ +public class UdpSender { + InetAddress inetAddress; + DatagramSocket sender; + boolean init; + + String address = null; + int port = -1; + + public UdpSender() { + } + + public UdpSender(String address, int port) { + this.address = address; + this.port = port; + initsocket(); + } + + public void send(Atom args[]) { + send(Atom.toOneString(args).getBytes()); + } + + public void send(int i) { + send(Integer.toString(i).getBytes()); + } + + public void send(float f) { + send(Float.toString(f).getBytes()); + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + initsocket(); + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + initsocket(); + } + + synchronized void initsocket() { + try { + sender = null; + inetAddress = InetAddress.getByName(address); + sender = new DatagramSocket(); + } catch (Exception e) { + throw new MaxRuntimeException(e); + } + } + + void send(byte buff[]) { + if ( sender == null ) + throw new MaxRuntimeException("UdpSender is not initialized"); + + try { + DatagramPacket packet = new DatagramPacket(buff, buff.length, inetAddress, port); + sender.send(packet); + } catch (IOException e) { + throw new MaxRuntimeException(e); + } + + } +} -- cgit v1.2.1