Package de.gmxhome.conrad.jpos.jpos_base
Class UdpIOProcessor
java.lang.Object
de.gmxhome.conrad.jpos.jpos_base.UniqueIOProcessor
de.gmxhome.conrad.jpos.jpos_base.UdpBaseIOProcessor
de.gmxhome.conrad.jpos.jpos_base.UdpIOProcessor
- All Implemented Interfaces:
AutoCloseable
,Runnable
Class to process UDP communication. Client communication means communication with one UDP socket, initiated by this
instance. Server socket communication adds the ability to communicate with several UDP sockets, initiated by this
socket or any other socket. Includes functionality for automatic data logging. Implementation is based on Java class
DatagramChannel.
Keep in mind: To allow correct message processing, the implementation has been made as follows:
Keep in mind: To allow correct message processing, the implementation has been made as follows:
- After open, before the first message has been received, getSource() will return 0.0.0.0:0.
- After the first message has been received, getSource() will always return the address of the sender of the last read message. After calling flush(), getSource() will return 0.0.0.0:0 again.
- In case of a multi-threaded application, ensure to synchronize read() and the corresponding getSource() call to ensure that the message will be assigned to the correct source.
- Before sending the first message, setTarget() must be used to set the target IP and port.
- If a response to an incoming message shall be sent, you can use setTarget(getSource) as long as no other message has been read.
- The target set by setTarget() is valid as long as another target will be set. In case of a multi-threaded application, ensure to synchronize setTarget() and the corresponding write() call to ensure that the message sent by write receives the correct target.
-
Nested Class Summary
Nested classes/interfaces inherited from class de.gmxhome.conrad.jpos.jpos_base.UdpBaseIOProcessor
UdpBaseIOProcessor.Frame
-
Field Summary
Fields inherited from class de.gmxhome.conrad.jpos.jpos_base.UdpBaseIOProcessor
OwnPort, Socket, SourceIP, TargetIP
Fields inherited from class de.gmxhome.conrad.jpos.jpos_base.UniqueIOProcessor
Dev, InitialPort, IOProcessorError, LoggingData, LoggingPrefix, LoggingType, LoggingTypeEscapeString, LoggingTypeHexString, LoggingTypeNoLogging, Port, Source, Target, Timeout
-
Constructor Summary
ConstructorsConstructorDescriptionUdpIOProcessor(JposDevice device, int ownport)
Stores JposDevice of derived IO processors and own port number. -
Method Summary
Methods inherited from class de.gmxhome.conrad.jpos.jpos_base.UdpBaseIOProcessor
available, close, flush, open, read, run, setTimeout, write
Methods inherited from class de.gmxhome.conrad.jpos.jpos_base.UniqueIOProcessor
location, logerror, logerror, logerror, setLoggingType, toLogString
-
Constructor Details
-
UdpIOProcessor
Stores JposDevice of derived IO processors and own port number. The device will be used for logging. The port number is the local port to be used to communicate with other sockets. If zero, a random port will be used.- Parameters:
device
- Device that uses the processor. Processor uses logging of device to produce logging entries.ownport
- Local port to be used by this socket.- Throws:
jpos.JposException
- Will not be thrown.
-
-
Method Details
-
setTarget
Sets target address for further write operations.- Overrides:
setTarget
in classUniqueIOProcessor
- Parameters:
addr
- communication target, e.g. 127.0.0.1:23456 for IPv4 and [12:34:56:78:9a:bc:de:f0]:23456 for IPv6.- Returns:
- Target in its internal String representation.
- Throws:
jpos.JposException
- If an error occurs.
-
getTarget
Description copied from class:UniqueIOProcessor
Retrieves currently set target for writing data.- Overrides:
getTarget
in classUniqueIOProcessor
- Returns:
- Current target device, null if target has not been specified.
-
getSource
Description copied from class:UniqueIOProcessor
Gets source of previously read data.- Overrides:
getSource
in classUniqueIOProcessor
- Returns:
- Data source, null before data have been read
-