#include <H3DNetworkingUtils/RemoteConnection.h>
Public Member Functions | |
virtual | ~RemoteConnection () |
void | setOpenCommsCallbackFn (CallbackFn fn, void *client_data) |
Set a function to be called when the communication channel is opened. | |
void | setCloseCommsCallbackFn (CallbackFn fn, void *client_data) |
Set a function to be called when the communication channel is closed. | |
virtual void | requestClose () |
Request closing the connection. | |
bool | closeRequested () const |
A close of the connection has been requested. | |
void | read (char *data, int num_bytes) |
reads from packet. | |
void | write (const char *data, int num_bytes) |
Write to the packet Note: nothing gets written to socket until write_packet.send() is called. | |
bool | hasSock () const |
Returns true if a socket has been created. | |
virtual void | showError (const char *msg) |
Sets the error message field. | |
virtual void | showInfo (const char *msg) |
Sets the info message field This can be routed to a string display mechanism. | |
virtual void | showInfo (const string msg) |
Sets the info message field This can be routed to a string display mechanism. | |
void | writeFieldHeader (int fld_id, bool with_timestamp) |
Write the id and time stamp to the write packet. | |
double | readDouble () |
Read a double from the read packet. | |
void | writeDouble (const double &val) |
Write a double to the write packet. | |
float | readFloat () |
Read a float from the read packet. | |
void | writeFloat (const float &val) |
Write a float to the write packet. | |
H3D::H3DFloat | readH3DFloat () |
Read a float from the read packet. | |
void | writeH3DFloat (const H3D::H3DFloat &val) |
Write a H3DFloat to the write packet. | |
virtual void | sendPacket () |
Write the 'write_packet' packet of data to socket If simulated latency is true, it may buffer the write_packet and send the next one off the buffer This is not virtual as it is not designed to be overridden Override sendPacket(Packet&) instead. | |
void | lockWriteThread () |
Lock the writing thread to avoid clashes with the reading thread when it occasionally needs to write. | |
void | unlockWriteThread () |
Unlock the writing thread . | |
Public Attributes | |
auto_ptr< H3D::SFString > | errorMessage |
Gets set if an error has occured - this can be routed to a message display access type: outputOnly basic type: SFString default value: "". | |
auto_ptr< H3D::SFString > | infoMessage |
Gets set if some info has occured that may be of interest to the user (such as the remote end disconnectiing) - this can be routed to a message display access type: outputOnly basic type: SFString default value: "". | |
auto_ptr< H3D::SFFloat > | simulatedLatency |
The simulated latency can be used to simulate a latency of a network The units are seconds It has a precision down to 1 mSec Note that simulated latency currently only works for periodicSend == TRUE. | |
auto_ptr< H3D::SFBool > | periodicSend |
If true, values are sent periodically from a looping 'send' thread If false they are sent when their values changes (typically from the graphics thread) When periodicSend is true, you can route to the field from something that is updated from a thread other than the graphics thread (eg haptics thread) access type: initializeOnly basic type: SFBool default value: FALSE. | |
auto_ptr< H3D::SFFloat > | periodicSendRate |
The rate (sends per second) the values are sent if periodicSend is true access type: initializeOnly basic type: SFFloat default value: 100. | |
auto_ptr< SFRemoteSync > | remoteSync |
An optional RemoteSync node that can be added (see RemoteSync.h) access type: initializeOnly basic type: SFNode default value:. | |
auto_ptr< BufferedSField < H3D::SFBool > > | isConnected |
Returns true if the connnection is established access type: outputOnly basic type: SFBool default value: flase. | |
Protected Member Functions | |
virtual void | receiveLoop () |
virtual void | sendLoop () |
The RemoteConnection class handles both TCP and UDP sockets, which is determined by the inheriting class. Sets up communications to and from another RemoteConnection node running on another application. This node operates in stand-alone mode, needing no other supporting objects in the scene-graph. In other words, it handles the connection and communication itself, regardless of what other communication is happening. It is, however, an abstract class. In order to work, the inheriting classes, RemoteServer or RemoteClient, RemoteUDPServer or RemoteUDPClient need to be instantiated. During normal operation, there is no difference in the way the server and client behave: both act as equal peers. It is only during connection and disconnection that there needs to be a difference. Note that operation of this class can be completely handled via the fields. The public functions are provided so that other classes in the library can call them.
Note : in this class "read" means read from a buffer or packet. "Receive" means receive from a socket. "write" means write to a buffer or packet. "Send" means send to a socket.
A word of warning... The order of the remoteFields is important. If two fields are set in a certain order on a remote machine and you expect them to be received in the same order, that will not necessarily be so. They will be received in the order they appear in the remoteFields list. This is because they are received in a reading thread (not the graphics thread). The graphics thread then extracts the values (if changed) during its collide phase, in the order of the remoteFields list.
RemoteConnection::~RemoteConnection | ( | ) | [virtual] |
if (receive_loop_threadP) { We have to explicitely cancel the receive thread becasue it might be blocked at a receive() call. receive_loop_threadP->cancel(); receive_loop_threadP->wait(); receive_loop_threadP = NULL; }
void H3DNetworkingUtils::RemoteConnection::write | ( | const char * | data, | |
int | num_bytes | |||
) | [inline] |
Write to the packet
Note: nothing gets written to socket until write_packet.send() is called.
Referenced by writeDouble(), and writeFloat().
void RemoteConnection::showError | ( | const char * | msg | ) | [virtual] |
Sets the error message field.
This can be routed to an error showing mechanism like LocalNodes::OKDialogBox.
Referenced by H3DNetworkingUtils::RemoteTCPClient::restartClient(), and H3DNetworkingUtils::RemoteUDPClient::sendThisPacket().
void RemoteConnection::sendPacket | ( | ) | [virtual] |
Write the 'write_packet' packet of data to socket
If simulated latency is true, it may buffer the write_packet and send the next one off the buffer
This is not virtual as it is not designed to be overridden
Override sendPacket(Packet&) instead.
References H3DNetworkingUtils::Packet::clear().
Referenced by H3DNetworkingUtils::RemoteUDPServer::sendLoop(), and H3DNetworkingUtils::RemoteUDPClient::sendLoop().
void H3DNetworkingUtils::RemoteConnection::lockWriteThread | ( | ) | [inline] |
Lock the writing thread to avoid clashes with the reading thread when it occasionally needs to write.
Referenced by H3DNetworkingUtils::RemoteUDPServer::sendLoop(), and H3DNetworkingUtils::RemoteUDPClient::sendLoop().
void RemoteConnection::receiveLoop | ( | ) | [protected, virtual] |
while (true) {
Reimplemented in H3DNetworkingUtils::RemoteUDPClient, and H3DNetworkingUtils::RemoteUDPServer.
References isConnected.
Referenced by H3DNetworkingUtils::RemoteTCPClient::clientReceiveLoop(), and H3DNetworkingUtils::RemoteTCPServer::startReceiving().
void RemoteConnection::sendLoop | ( | ) | [protected, virtual] |
while (true) {
Reimplemented in H3DNetworkingUtils::RemoteUDPClient, and H3DNetworkingUtils::RemoteUDPServer.
References isConnected.
auto_ptr<H3D::SFFloat > H3DNetworkingUtils::RemoteConnection::simulatedLatency |
The simulated latency can be used to simulate a latency of a network
The units are seconds It has a precision down to 1 mSec
Note that simulated latency currently only works for periodicSend == TRUE.
access type: inputOutput
basic type: SFFloat
default value: "0"