WOscTcpClient Class Reference

Inherits WOscTcpHandler.

List of all members.

Public Member Functions

 WOscTcpClient (bool threading=true)
Error Connect (const TheNetReturnAddress &serverAddress)
Error Close ()

Protected Member Functions

virtual void HandleOffendingPackets (const char *const data, int dataLen, const WOscException &exception)
virtual void HandleNonmatchedMessages (const WOscMessage *msg, const WOscNetReturn *networkReturnAddress)

Detailed Description



Definition at line 13 of file WOscTcpClient.h.

Constructor & Destructor Documentation

WOscTcpClient::WOscTcpClient ( bool  threading = true  ) 

WOscTCPClient.cpp - A streaming OSC client using posix threads and sockets

Created on: Apr 21, 2010 Author: uli Implements a full featured OSC client with TCP transport.

threading If true, all reception happens in a separate thread and does not require any select logic in the main loop, but you have to take care when calling main thread code from the OSC message handlers/methods. If false, threading is disabled and the reception must be implemented by a select statement. On input WOscTcpClient::NetworkReceive() must be called. The socket is switched to non blocking automatically. See the streaming server example for further details.

Definition at line 25 of file WOscTcpClient.cpp.

00025                                            : WOscTcpHandler(threading)
00026 {}

Member Function Documentation

WOscTcpClient::Error WOscTcpClient::Close (  ) 

Close the receiving socket and shutdown the receiving thread if in threading mode.

Definition at line 74 of file WOscTcpClient.cpp.

References WOscTcpHandler::GetSocketID(), WOscTcpHandler::Stop(), WOscTcpHandler::WOS_ERR_ALREADY_CLOSED, and WOscTcpHandler::WOS_ERR_DISCONNECTED.

00075 {
00076     // Check if reception thread has already been shut down
00077     if ( GetThreading() && GetRxThreadID() )
00078         return WOS_ERR_ALREADY_CLOSED;
00079     // Check if socket still
00080     if ( GetSocketID() < 0 )
00081         return WOS_ERR_DISCONNECTED;
00083     WOscTcpHandler::Error err = Stop();
00085     // close socket
00086     int ret = close(GetSocketID());
00087     if ( ret ) {
00088 //      std::cout<<"Close failed."<<std::endl;
00089     }
00090     return err;
00091 }

WOscTcpClient::Error WOscTcpClient::Connect ( const TheNetReturnAddress serverAddress  ) 

Try to open a connection to a remote server. Establishes a connection to a remote server and creates a separate thread for reception of server replies.

Connect to a OSC server at a given address. Starts a receiver thread which handles any replies from the server when this class was constructed with threading enabled. If not, the socket is set to non blocking and can be used in a select statement.

Definition at line 39 of file WOscTcpClient.cpp.

References WOscTcpHandler::GetSocketID(), WOscTcpHandler::WOS_ERR_ALREADY_CONNECTED, WOscTcpHandler::WOS_ERR_ALREADY_RUNNING, WOscTcpHandler::WOS_ERR_NO_ERROR, WOscTcpHandler::WOS_ERR_SOCKET_CONNECT, and WOscTcpHandler::WOS_ERR_SOCKET_CREATE.

00040 {
00041     // Check if reception thread is already running
00042     if ( GetRxThreadID() > 0 )
00043         return WOS_ERR_ALREADY_RUNNING;
00045     // Check if someone established a connection already
00046     if ( GetSocketID() >= 0 )
00047         return WOS_ERR_ALREADY_CONNECTED;
00049     // Create socket
00050     int sock = socket(AF_INET, SOCK_STREAM, 0);
00051     if (sock < 0) {
00052         return WOS_ERR_SOCKET_CREATE;
00053     }
00055     // Connect
00056     int ret = connect(sock, (struct sockaddr*) &serverAddress.m_addr, sizeof(serverAddress.m_addr));
00057     if ( ret < 0 ) {
00058         close(sock);
00059         return WOS_ERR_SOCKET_CONNECT;
00060     }
00062     // starts thread if threading is enabled
00063     WOscTcpHandler::Error err = Start(sock, serverAddress);
00064     if ( err != WOscTcpHandler::WOS_ERR_NO_ERROR )
00065         close(sock);
00067     return err;
00068 }

virtual void WOscTcpClient::HandleNonmatchedMessages ( const WOscMessage msg,
const WOscNetReturn networkReturnAddress 
) [inline, protected, virtual]

Handler for OSC messages which didn't match any address in the OSC address space. The user can define an own action by overriding this pure virtual function.

msg Pointer to Message which hasn't been processed.
networkReturnAddress Network address of the sender of this message.

Implements WOscReceiver.


Definition at line 27 of file WOscTcpClient.h.

00028                                                        { }

virtual void WOscTcpClient::HandleOffendingPackets ( const char *const   data,
int  dataLen,
const WOscException exception 
) [inline, protected, virtual]

Handler for packets which caused either an internal exception or another error. The user can decide what to do with such packets by overriding this function.

data Pointer to the buffer containing the offending packet data.
dataLen Lenght of the buffer containg the offending packet data.
exception Exception which has been generated during processing this packet.

Implements WOscReceiver.

Definition at line 25 of file WOscTcpClient.h.

00026                                             { }

The documentation for this class was generated from the following files:
Generated on Sat Oct 23 03:05:59 2010 for WOscLib by  doxygen 1.6.3