|
||||||||||
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!
OSCClient
,
OSCServer
,
OSCReceiver
Field Summary | |
---|---|
protected boolean |
allocBuf
|
protected ByteBuffer |
byteBuf
|
protected int |
dumpMode
|
protected InetSocketAddress |
localAddress
|
protected PrintStream |
printStream
|
protected boolean |
revivable
|
protected Object |
sync
|
protected SocketAddress |
target
|
Fields inherited from interface de.sciss.net.OSCChannel |
---|
DEFAULTBUFSIZE, kDumpBoth, kDumpHex, kDumpOff, kDumpText, TCP, UDP |
Constructor Summary | |
---|---|
protected |
OSCTransmitter(OSCPacketCodec c,
String protocol,
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,
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 SelectableChannel |
getChannel()
|
OSCPacketCodec |
getCodec()
Queries the codec used in packet coding and decoding. |
abstract InetSocketAddress |
getLocalAddress()
Queries the transmitter's local socket address. |
protected InetSocketAddress |
getLocalAddress(InetAddress addr,
int port)
|
String |
getProtocol()
Queries the transport protocol used by this communicator. |
abstract boolean |
isConnected()
Queries the connection state of the transmitter. |
static OSCTransmitter |
newUsing(DatagramChannel dch)
Creates a new instance of an OSCTransmitter , using
default codec and UDP transport on a given channel. |
static OSCTransmitter |
newUsing(OSCPacketCodec c,
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,
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,
String protocol)
Creates a new instance of an OSCTransmitter , using
a specific codec and transport protocol. |
static OSCTransmitter |
newUsing(OSCPacketCodec c,
String protocol,
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,
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,
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(SocketChannel sch)
Creates a new instance of an OSCTransmitter , using
default codec and TCP transport on a given channel. |
static OSCTransmitter |
newUsing(String protocol)
Creates a new instance of an OSCTransmitter , using
default codec and a specific transport protocol. |
static OSCTransmitter |
newUsing(String protocol,
InetSocketAddress localAddress)
Creates a new instance of an OSCTransmitter , using
default codec and a specific transport protocol and local socket address. |
static OSCTransmitter |
newUsing(String protocol,
int port)
Creates a new instance of an OSCTransmitter , using
default codec and a specific transport protocol and port. |
static OSCTransmitter |
newUsing(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,
SocketAddress target)
Sends an OSC packet (bundle or message) to the given network address, using a particular codec. |
void |
send(OSCPacket p,
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(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 Object sync
protected boolean allocBuf
protected ByteBuffer byteBuf
protected int dumpMode
protected PrintStream printStream
protected SocketAddress target
protected final InetSocketAddress localAddress
protected final boolean revivable
Constructor Detail |
---|
protected OSCTransmitter(OSCPacketCodec c, String protocol, InetSocketAddress localAddress, boolean revivable)
Method Detail |
---|
public static OSCTransmitter newUsing(String protocol) throws 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
IOException
- if a networking error occurs while creating the socket
IllegalArgumentException
- if an illegal protocol is usedOSCChannel.UDP
,
OSCChannel.TCP
,
getLocalAddress()
public static OSCTransmitter newUsing(OSCPacketCodec c, String protocol) throws 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
IOException
- if a networking error occurs while creating the socket
IllegalArgumentException
- if an illegal protocol is usedOSCChannel.UDP
,
OSCChannel.TCP
,
getLocalAddress()
public static OSCTransmitter newUsing(String protocol, int port) throws 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 TCP
port
- the port number for the OSC socket, or 0
to use an arbitrary free port
IOException
- if a networking error occurs while creating the socket
IllegalArgumentException
- if an illegal protocol is usedpublic static OSCTransmitter newUsing(OSCPacketCodec c, String protocol, int port) throws 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 TCP
port
- the port number for the OSC socket, or 0
to use an arbitrary free port
IOException
- if a networking error occurs while creating the socket
IllegalArgumentException
- if an illegal protocol is usedpublic static OSCTransmitter newUsing(String protocol, int port, boolean loopBack) throws 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 TCP
port
- 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
special IP "0.0.0.0"
is used which means any local host is picked
IOException
- if a networking error occurs while creating the socket
IllegalArgumentException
- if an illegal protocol is usedpublic static OSCTransmitter newUsing(OSCPacketCodec c, String protocol, int port, boolean loopBack) throws 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 TCP
port
- 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
special IP "0.0.0.0"
is used which means any local host is picked
IOException
- if a networking error occurs while creating the socket
IllegalArgumentException
- if an illegal protocol is usedpublic static OSCTransmitter newUsing(String protocol, InetSocketAddress localAddress) throws 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 TCP
localAddress
- 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).
IOException
- if a networking error occurs while creating the socket
IllegalArgumentException
- if an illegal protocol is usedpublic static OSCTransmitter newUsing(OSCPacketCodec c, String protocol, InetSocketAddress localAddress) throws 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 TCP
localAddress
- 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).
IOException
- if a networking error occurs while creating the socket
IllegalArgumentException
- if an illegal protocol is usedpublic static OSCTransmitter newUsing(DatagramChannel dch) throws 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.
IOException
- if a networking error occurs while configuring the socketpublic static OSCTransmitter newUsing(OSCPacketCodec c, DatagramChannel dch) throws 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.
IOException
- if a networking error occurs while configuring the socketpublic static OSCTransmitter newUsing(SocketChannel sch) throws 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.
IOException
- if a networking error occurs while configuring the socketpublic static OSCTransmitter newUsing(OSCPacketCodec c, SocketChannel sch) throws 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.
IOException
- if a networking error occurs while configuring the socketpublic String getProtocol()
OSCChannel
getProtocol
in interface OSCChannel
UDP
or TCP
OSCChannel.UDP
,
OSCChannel.TCP
public abstract InetSocketAddress getLocalAddress() throws IOException
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 OSCChannel
IOException
- if the local host could not be resolvedInetSocketAddress.getHostName()
,
InetSocketAddress.getAddress()
,
InetSocketAddress.getPort()
public void setTarget(SocketAddress target)
send( OSCPacket )
.
target
- the address of the remote target socket. Usually you construct an appropriate InetSocketAddress
InetSocketAddress
public void setCodec(OSCPacketCodec c)
OSCChannel
setCodec
in interface OSCChannel
c
- the codec to usepublic OSCPacketCodec getCodec()
OSCChannel
getCodec
in interface OSCChannel
OSCPacketCodec.getDefaultCodec()
public abstract void connect() throws 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.
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()
protected InetSocketAddress getLocalAddress(InetAddress addr, int port) throws UnknownHostException
UnknownHostException
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, SocketAddress target) throws IOException
p
- the packet to sendtarget
- the target address to send the packet to
IOException
- if a write error, OSC encoding error,
buffer overflow error or network error occurspublic abstract void send(OSCPacketCodec c, OSCPacket p, SocketAddress target) throws IOException
c
- the codec to usep
- the packet to sendtarget
- the target address to send the packet to
IOException
- if a write error, OSC encoding error,
buffer overflow error or network error occurspublic final void send(OSCPacket p) throws IOException
setTarget
method. Therefore
this will throw a NullPointerException
if
no default address was specified.
p
- the packet to send
IOException
- if a write error, OSC encoding error,
buffer overflow error or network error occurs
NullPointerException
- if no default address was specifiedsetTarget( SocketAddress )
public abstract void send(OSCPacketCodec c, OSCPacket p) throws IOException
setTarget
method. Therefore
this will throw a NullPointerException
if
no default address was specified.
c
- the codec to usep
- the packet to send
IOException
- if a write error, OSC encoding error,
buffer overflow error or network error occurs
NullPointerException
- if no default address was specifiedsetTarget( SocketAddress )
public void setBufferSize(int size)
OSCChannel
setBufferSize
in interface OSCChannel
size
- the new size in bytes.OSCChannel.getBufferSize()
public int getBufferSize()
OSCChannel
getBufferSize
in interface OSCChannel
OSCChannel.setBufferSize( int )
public void dumpOSC(int mode, PrintStream stream)
OSCChannel
dumpOSC
in interface OSCChannel
mode
- 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.err
OSCChannel.kDumpOff
,
OSCChannel.kDumpText
,
OSCChannel.kDumpHex
,
OSCChannel.kDumpBoth
public void dispose()
OSCChannel
dispose
in interface OSCChannel
protected void checkBuffer()
protected abstract SelectableChannel getChannel()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |