Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Deprecated/UDP.Unix/UnixSocketSender.cpp

Go to the documentation of this file.
00001 #include "UnixSocketSender.hpp"
00002 
00003 UnixSocketSender::UnixSocketSender( char*  SendMsg_Host,
00004                                     short  SendMsg_Port )
00005 {
00006    ListenSocket = INVALID_SOCKET;
00007 
00008    memset( &dest,  0, sizeof( struct sockaddr_in ) );
00009 
00010    getHostData( SendMsg_Host );
00011 
00012    dest.sin_family = PF_INET;
00013    dest.sin_addr   = *(in_addr*)( hostdata->h_addr_list[0] );
00014    dest.sin_port   = htons( SendMsg_Port );
00015 }
00016 
00017 // ::SendMsg
00018 // hostdata -> dest
00019 // dest
00020 // sento( ListenSocket, ... )
00021 
00022 // ::Listen()
00023 // ListenSocket
00024 // srv
00025 
00026 // ::ListenThread()
00027 // socketData
00028 // client
00029 
00030 UnixSocketSender::~UnixSocketSender() { }
00031 
00032 inline void UnixSocketSender::setSocket( SOCKET fdSocketNo ) {
00033   ListenSocket = fdSocketNo;  
00034 }
00035 
00036 bool UnixSocketSender::SendMsg( char* Msg, size_t msgLen )
00037 {
00038    signed int Sent;
00039 
00040    printf( "Message being sent to host %s port %i\n",
00041            inet_ntoa( dest.sin_addr ),
00042            ntohs(     dest.sin_port )
00043          );
00044  
00045    Sent = sendto( ListenSocket, Msg, msgLen, 0, 
00046                   (struct sockaddr *)&dest, 
00047                   sizeof( struct sockaddr_in ) 
00048                 );
00049 
00050    if ( Sent != msgLen )
00051    {
00052       printf("Error sending UDP packet from listen socket\n");
00053       fflush(0);
00054       return false;
00055    }
00056 
00057    return true;
00058 }
00059 
00060 void UnixSocketSender::getHostData( char* SendMsg_Host )
00061 {
00062    if ( atoi( SendMsg_Host) ) // Host is given by IPv4 format "x.x.x.x"  
00063    {
00064       ULONG ip = inet_addr( SendMsg_Host );
00065       hostdata = gethostbyaddr( (char*)&ip, sizeof(ip), PF_INET );
00066  
00067    } else {          // Host is given by name format "server.host.ca"
00068 
00069       hostdata = gethostbyname( SendMsg_Host );
00070    }
00071 
00072    if ( hostdata == NULL )
00073    {
00074       printf( "Error getting host address\n" );
00075       fflush( 0 );   
00076       exit( 1 );
00077    }
00078 }

Generated on Sun Oct 14 18:46:30 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001