|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.sciss.net.OSCTransmitter
public abstract class OSCTransmitter
A class that sends OSC packets (messages
or bundles) to a target OSC server. Each instance takes
a network channel, either explictly specified by a
DatagramChannel (for UDP) or SocketChannel (for TCP),
or internally opened when a protocol type is specified.
Messages are send by invoking one
of the send methods. For an example,
please refer to the OSCReceiver document.
Note that as of v0.3, you will most likely want to use preferably one of OSCClient or OSCServer
over OSCTransmitter. Also note that as of v0.3, OSCTransmitter is abstract, which
renders direct instantiation impossible. To update old code, occurences of new OSCTransmitter()
must be replaced by one of the OSCTransmitter.newUsing methods!
Note that someone has reported trouble with the InetAddress.getLocalHost() method
on a machine that has no proper IP configuration or DNS problems. In such a case when you need
to communicate only on this machine and not a network, you can still bind the channel
to the special address "127.0.0.1" (called "loopback").
OSCClient,
OSCServer,
OSCReceiver| Field Summary | |
|---|---|
protected boolean |
allocBuf
|
protected java.nio.ByteBuffer |
byteBuf
|
protected int |
dumpMode
|
protected java.net.InetSocketAddress |
localAddress
|
protected java.io.PrintStream |
printStream
|
protected boolean |
revivable
|
protected java.lang.Object |
sync
|
protected java.net.SocketAddress |
target
|
| Fields inherited from interface de.sciss.net.OSCChannel |
|---|
DEFAULTBUFSIZE, kDumpBoth, kDumpHex, kDumpOff, kDumpText, TCP, UDP |
| Constructor Summary | |
|---|---|
protected |
OSCTransmitter(OSCPacketCodec c,
java.lang.String protocol,
java.net.InetSocketAddress localAddress,
boolean revivable)
|
| Method Summary | |
|---|---|
protected void |
checkBuffer()
|
abstract void |
connect()
Establishes connection for transports requiring connectivity (e.g. |
void |
dispose()
Disposes the resources associated with the OSC communicator. |
void |
dumpOSC(int mode,
java.io.PrintStream stream)
Changes the way processed OSC messages are printed to the standard err console. |
int |
getBufferSize()
Queries the buffer size used for coding or decoding OSC messages. |
protected abstract java.nio.channels.SelectableChannel |
getChannel()
|
OSCPacketCodec |
getCodec()
Queries the codec used in packet coding and decoding. |
abstract java.net.InetSocketAddress |
getLocalAddress()
Queries the transmitter's local socket address. |
java.lang.String |
getProtocol()
Queries the transport protocol used by this communicator. |
abstract boolean |
isConnected()
Queries the connection state of the transmitter. |
static OSCTransmitter |
newUsing(java.nio.channels.DatagramChannel dch)
Creates a new instance of an OSCTransmitter, using
default codec and UDP transport on a given channel. |
static OSCTransmitter |
newUsing(OSCPacketCodec c,
java.nio.channels.DatagramChannel dch)
Creates a new instance of an OSCTransmitter, using
a specific codec and UDP transport on a given channel. |
static OSCTransmitter |
newUsing(OSCPacketCodec c,
java.nio.channels.SocketChannel sch)
Creates a new instance of an OSCTransmitter, using
a specific codec and TCP transport on a given channel. |
static OSCTransmitter |
newUsing(OSCPacketCodec c,
java.lang.String protocol)
Creates a new instance of an OSCTransmitter, using
a specific codec and transport protocol. |
static OSCTransmitter |
newUsing(OSCPacketCodec c,
java.lang.String protocol,
java.net.InetSocketAddress localAddress)
Creates a new instance of an OSCTransmitter, using
a specific codec and transport protocol and local socket address. |
static OSCTransmitter |
newUsing(OSCPacketCodec c,
java.lang.String protocol,
int port)
Creates a new instance of an OSCTransmitter, using
a specific codec and transport protocol and port. |
static OSCTransmitter |
newUsing(OSCPacketCodec c,
java.lang.String protocol,
int port,
boolean loopBack)
Creates a new instance of an OSCTransmitter, using
a specific codec and transport protocol and port. |
static OSCTransmitter |
newUsing(java.nio.channels.SocketChannel sch)
Creates a new instance of an OSCTransmitter, using
default codec and TCP transport on a given channel. |
static OSCTransmitter |
newUsing(java.lang.String protocol)
Creates a new instance of an OSCTransmitter, using
default codec and a specific transport protocol. |
static OSCTransmitter |
newUsing(java.lang.String protocol,
java.net.InetSocketAddress localAddress)
Creates a new instance of an OSCTransmitter, using
default codec and a specific transport protocol and local socket address. |
static OSCTransmitter |
newUsing(java.lang.String protocol,
int port)
Creates a new instance of an OSCTransmitter, using
default codec and a specific transport protocol and port. |
static OSCTransmitter |
newUsing(java.lang.String protocol,
int port,
boolean loopBack)
Creates a new instance of an OSCTransmitter, using
default codec and a specific transport protocol and port. |
void |
send(OSCPacket p)
Sends an OSC packet (bundle or message) to the default network address, using the current codec. |
abstract void |
send(OSCPacketCodec c,
OSCPacket p)
Sends an OSC packet (bundle or message) to the default network address, using a particular codec. |
abstract void |
send(OSCPacketCodec c,
OSCPacket p,
java.net.SocketAddress target)
Sends an OSC packet (bundle or message) to the given network address, using a particular codec. |
void |
send(OSCPacket p,
java.net.SocketAddress target)
Sends an OSC packet (bundle or message) to the given network address, using the current codec. |
void |
setBufferSize(int size)
Adjusts the buffer size for OSC messages. |
void |
setCodec(OSCPacketCodec c)
Specifies which codec is used in packet coding and decoding. |
void |
setTarget(java.net.SocketAddress target)
Specifies the transmitter's target address, that is the address of the remote side to talk to. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final java.lang.Object sync
protected boolean allocBuf
protected java.nio.ByteBuffer byteBuf
protected int dumpMode
protected java.io.PrintStream printStream
protected java.net.SocketAddress target
protected final java.net.InetSocketAddress localAddress
protected final boolean revivable
| Constructor Detail |
|---|
protected OSCTransmitter(OSCPacketCodec c,
java.lang.String protocol,
java.net.InetSocketAddress localAddress,
boolean revivable)
| Method Detail |
|---|
public static OSCTransmitter newUsing(java.lang.String protocol)
throws java.io.IOException
OSCTransmitter, using
default codec and a specific transport protocol. It picks an arbitrary free port
and uses the local machine's IP. To determine the resulting
port, you can use getLocalAddress afterwards.
protocol - the protocol to use, currently either UDP or TCP
java.io.IOException - if a networking error occurs while creating the socket
java.lang.IllegalArgumentException - if an illegal protocol is usedOSCChannel.UDP,
OSCChannel.TCP,
getLocalAddress()
public static OSCTransmitter newUsing(OSCPacketCodec c,
java.lang.String protocol)
throws java.io.IOException
OSCTransmitter, using
a specific codec and transport protocol. It picks an arbitrary free port
and uses the local machine's IP. To determine the resulting
port, you can use getLocalAddress afterwards.
c - the codec to useprotocol - the protocol to use, currently either UDP or TCP
java.io.IOException - if a networking error occurs while creating the socket
java.lang.IllegalArgumentException - if an illegal protocol is usedOSCChannel.UDP,
OSCChannel.TCP,
getLocalAddress()
public static OSCTransmitter newUsing(java.lang.String protocol,
int port)
throws java.io.IOException
OSCTransmitter, using
default codec and a specific transport protocol and port. It
uses the local machine's IP. Note that the port specifies the
local socket, not the remote (or target) port. This can be set
using the setTarget method!
protocol - the protocol to use, currently either UDP or TCPport - the port number for the OSC socket, or 0 to use an arbitrary free port
java.io.IOException - if a networking error occurs while creating the socket
java.lang.IllegalArgumentException - if an illegal protocol is used
public static OSCTransmitter newUsing(OSCPacketCodec c,
java.lang.String protocol,
int port)
throws java.io.IOException
OSCTransmitter, using
a specific codec and transport protocol and port. It
uses the local machine's IP. Note that the port specifies the
local socket, not the remote (or target) port. This can be set
using the setTarget method!
c - the codec to useprotocol - the protocol to use, currently either UDP or TCPport - the port number for the OSC socket, or 0 to use an arbitrary free port
java.io.IOException - if a networking error occurs while creating the socket
java.lang.IllegalArgumentException - if an illegal protocol is used
public static OSCTransmitter newUsing(java.lang.String protocol,
int port,
boolean loopBack)
throws java.io.IOException
OSCTransmitter, using
default codec and a specific transport protocol and port. It
uses the local machine's IP or the "loopback" address.
Note that the port specifies the
local socket, not the remote (or target) port. This can be set
using the setTarget method!
protocol - the protocol to use, currently either UDP or TCPport - the port number for the OSC socket, or 0 to use an arbitrary free portloopBack - if true, the "loopback" address ("127.0.0.1")
is used which limits communication to the local machine. If false, the
local machine's regular IP address is used.
java.io.IOException - if a networking error occurs while creating the socket
java.lang.IllegalArgumentException - if an illegal protocol is used
public static OSCTransmitter newUsing(OSCPacketCodec c,
java.lang.String protocol,
int port,
boolean loopBack)
throws java.io.IOException
OSCTransmitter, using
a specific codec and transport protocol and port. It
uses the local machine's IP or the "loopback" address.
Note that the port specifies the
local socket, not the remote (or target) port. This can be set
using the setTarget method!
c - the codec to useprotocol - the protocol to use, currently either UDP or TCPport - the port number for the OSC socket, or 0 to use an arbitrary free portloopBack - if true, the "loopback" address ("127.0.0.1")
is used which limits communication to the local machine. If false, the
local machine's regular IP address is used.
java.io.IOException - if a networking error occurs while creating the socket
java.lang.IllegalArgumentException - if an illegal protocol is used
public static OSCTransmitter newUsing(java.lang.String protocol,
java.net.InetSocketAddress localAddress)
throws java.io.IOException
OSCTransmitter, using
default codec and a specific transport protocol and local socket address.
Note that localAddress specifies the
local socket, not the remote (or target) socket. This can be set
using the setTarget method!
protocol - the protocol to use, currently either UDP or TCPlocalAddress - a valid address to use for the OSC socket. If the port is 0,
an arbitrary free port is picked when the transmitter is connected. (you can find out
the actual port in this case by calling getLocalAddress() after the
transmitter was connected).
java.io.IOException - if a networking error occurs while creating the socket
java.lang.IllegalArgumentException - if an illegal protocol is used
public static OSCTransmitter newUsing(OSCPacketCodec c,
java.lang.String protocol,
java.net.InetSocketAddress localAddress)
throws java.io.IOException
OSCTransmitter, using
a specific codec and transport protocol and local socket address.
Note that localAddress specifies the
local socket, not the remote (or target) socket. This can be set
using the setTarget method!
c - the codec to useprotocol - the protocol to use, currently either UDP or TCPlocalAddress - a valid address to use for the OSC socket. If the port is 0,
an arbitrary free port is picked when the transmitter is connected. (you can find out
the actual port in this case by calling getLocalAddress() after the
transmitter was connected).
java.io.IOException - if a networking error occurs while creating the socket
java.lang.IllegalArgumentException - if an illegal protocol is used
public static OSCTransmitter newUsing(java.nio.channels.DatagramChannel dch)
throws java.io.IOException
OSCTransmitter, using
default codec and UDP transport on a given channel. The caller should ensure that
the provided channel's socket was bound to a valid address
(using dch.socket().bind( SocketAddress )).
Note that dch specifies the
local socket, not the remote (or target) socket. This can be set
using the setTarget method!
dch - the DatagramChannel to use as UDP socket.
java.io.IOException - if a networking error occurs while configuring the socket
public static OSCTransmitter newUsing(OSCPacketCodec c,
java.nio.channels.DatagramChannel dch)
throws java.io.IOException
OSCTransmitter, using
a specific codec and UDP transport on a given channel. The caller should ensure that
the provided channel's socket was bound to a valid address
(using dch.socket().bind( SocketAddress )).
Note that dch specifies the
local socket, not the remote (or target) socket. This can be set
using the setTarget method!
c - the codec to usedch - the DatagramChannel to use as UDP socket.
java.io.IOException - if a networking error occurs while configuring the socket
public static OSCTransmitter newUsing(java.nio.channels.SocketChannel sch)
throws java.io.IOException
OSCTransmitter, using
default codec and TCP transport on a given channel. The caller should ensure that
the provided channel's socket was bound to a valid address
(using sch.socket().bind( SocketAddress )). Furthermore,
the channel must be connected (using connect()) before
being able to transmit messages.
Note that sch specifies the
local socket, not the remote (or target) socket. This can be set
using the setTarget method!
sch - the SocketChannel to use as TCP socket.
java.io.IOException - if a networking error occurs while configuring the socket
public static OSCTransmitter newUsing(OSCPacketCodec c,
java.nio.channels.SocketChannel sch)
throws java.io.IOException
OSCTransmitter, using
a specific codec and TCP transport on a given channel. The caller should ensure that
the provided channel's socket was bound to a valid address
(using sch.socket().bind( SocketAddress )). Furthermore,
the channel must be connected (using connect()) before
being able to transmit messages.
Note that sch specifies the
local socket, not the remote (or target) socket. This can be set
using the setTarget method!
c - the codec to usesch - the SocketChannel to use as TCP socket.
java.io.IOException - if a networking error occurs while configuring the socketpublic java.lang.String getProtocol()
OSCChannel
getProtocol in interface OSCChannelUDP or TCPOSCChannel.UDP,
OSCChannel.TCPpublic abstract java.net.InetSocketAddress getLocalAddress()
getHostName() (or for the IP getAddress().getHostAddress())
and getPort(). This port number may be 0
if the transmitter was called with an unspecified port and has not yet been
connected. In this case, to determine the port actually used, call this
method after the transmitter has been connected.
getLocalAddress in interface OSCChannelInetSocketAddress.getHostName(),
InetSocketAddress.getAddress(),
InetSocketAddress.getPort()public void setTarget(java.net.SocketAddress target)
send( OSCPacket ).
target - the address of the remote target socket. Usually you construct an appropriate InetSocketAddressInetSocketAddresspublic void setCodec(OSCPacketCodec c)
OSCChannel
setCodec in interface OSCChannelc - the codec to usepublic OSCPacketCodec getCodec()
OSCChannel
getCodec in interface OSCChannelOSCPacketCodec.getDefaultCodec()
public abstract void connect()
throws java.io.IOException
When a UDP transmitter
is created without an explicit DatagramChannel – say by
calling OSCTransmitter.newUsing( "udp" ), you are required
to call connect() so that an actual DatagramChannel is
created and bound. For a UDP transmitter which was created with an explicit
DatagramChannel, this method does noting, so it is always safe
to call connect(). However, for TCP transmitters,
this may throw an IOException if the transmitter
was already connected, therefore be sure to check isConnected() before.
java.io.IOException - if a networking error occurs. Possible reasons: - the underlying
network channel had been closed by the server. - the transport
is TCP and the server is not available. - the transport is TCP
and an OSCReceiver sharing the same socket was stopped before (unable to revive).isConnected()public abstract boolean isConnected()
true if the transmitter is connected, false otherwise. For transports that do not use
connectivity (e.g. UDP) this returns false, if the
underlying DatagramChannel has not yet been created.connect()
public final void send(OSCPacket p,
java.net.SocketAddress target)
throws java.io.IOException
p - the packet to sendtarget - the target address to send the packet to
java.io.IOException - if a write error, OSC encoding error,
buffer overflow error or network error occurs
public abstract void send(OSCPacketCodec c,
OSCPacket p,
java.net.SocketAddress target)
throws java.io.IOException
c - the codec to usep - the packet to sendtarget - the target address to send the packet to
java.io.IOException - if a write error, OSC encoding error,
buffer overflow error or network error occurs
public final void send(OSCPacket p)
throws java.io.IOException
setTarget method. Therefore
this will throw a NullPointerException if
no default address was specified.
p - the packet to send
java.io.IOException - if a write error, OSC encoding error,
buffer overflow error or network error occurs
java.lang.NullPointerException - if no default address was specifiedsetTarget( SocketAddress )
public abstract void send(OSCPacketCodec c,
OSCPacket p)
throws java.io.IOException
setTarget method. Therefore
this will throw a NullPointerException if
no default address was specified.
c - the codec to usep - the packet to send
java.io.IOException - if a write error, OSC encoding error,
buffer overflow error or network error occurs
java.lang.NullPointerException - if no default address was specifiedsetTarget( SocketAddress )public void setBufferSize(int size)
OSCChannel
setBufferSize in interface OSCChannelsize - the new size in bytes.OSCChannel.getBufferSize()public int getBufferSize()
OSCChannel
getBufferSize in interface OSCChannelOSCChannel.setBufferSize( int )
public void dumpOSC(int mode,
java.io.PrintStream stream)
OSCChannel
dumpOSC in interface OSCChannelmode - one of kDumpOff (don't dump, default),
kDumpText (dump human readable string),
kDumpHex (hexdump), or
kDumpBoth (both text and hex)stream - the stream to print on, or null which
is shorthand for System.errOSCChannel.kDumpOff,
OSCChannel.kDumpText,
OSCChannel.kDumpHex,
OSCChannel.kDumpBothpublic void dispose()
OSCChannel
dispose in interface OSCChannelprotected void checkBuffer()
protected abstract java.nio.channels.SelectableChannel getChannel()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||