oldfart
Member
Hi guys,
If anyone is interested in a VC++ UDP LAN Advertising server with an associated Secure TCP/IP Client/Listen Server please let me know. Both the Advertising server and the Listen server live on the same port.
I use it to detect other instances of my YASAMM/VNetCafe application running on a LAN.
Note: I then use another layer to allow Remote Procedure Calls (RPC) to be performed between the Applications.
The advertising Server (Ping Master) and the Secure Client are at one end.
The Ping Slave and the Listen Server are at the other end
It uses:-
A class CLocalUdpP2P - a CWinThread Object with an API that is the same at both ends, it is a non blocking and message driven stand alone object.
It handles:-
1. A Master Advertising Server (by sending a Ping) UDP CAsyncSocket, using SO_REUSEADDR and SO_BROADCAST
2. A Secure TCP/IP Client that will Connect to a Listen Server and hence another Secure Client
3. Slave UDP CAyncSocket Response to the Ping - including Listen Server info
4. A TCP/IP Listen Server that Accepts Connections and creates a secure TCP/IP session.
UdpSocket.h
UdpSocket.cpp
cheers
OldFart
If anyone is interested in a VC++ UDP LAN Advertising server with an associated Secure TCP/IP Client/Listen Server please let me know. Both the Advertising server and the Listen server live on the same port.
I use it to detect other instances of my YASAMM/VNetCafe application running on a LAN.
Note: I then use another layer to allow Remote Procedure Calls (RPC) to be performed between the Applications.
The advertising Server (Ping Master) and the Secure Client are at one end.
The Ping Slave and the Listen Server are at the other end
It uses:-
A class CLocalUdpP2P - a CWinThread Object with an API that is the same at both ends, it is a non blocking and message driven stand alone object.
It handles:-
1. A Master Advertising Server (by sending a Ping) UDP CAsyncSocket, using SO_REUSEADDR and SO_BROADCAST
2. A Secure TCP/IP Client that will Connect to a Listen Server and hence another Secure Client
3. Slave UDP CAyncSocket Response to the Ping - including Listen Server info
4. A TCP/IP Listen Server that Accepts Connections and creates a secure TCP/IP session.
UdpSocket.h
Code:
class CUdpSocket : public CAsyncSocket
{
public:
CUdpSocket();
virtual ~CUdpSocket();
...
// Operations
public:
// Overide the ASyncSocket Create to allow handle Reuse and Broadcast
bool Create( HWND hWndParent,
CWinThread *ptParentWinThread,
CString &rcsWinIpAddress,
int &rnWinPort,
BOOL fBroadcast = FALSE,
int nSocketType = SOCK_DGRAM,
long lEvent = FD_READ | FD_WRITE );
UdpSocket.cpp
Code:
bool CUdpSocket::Create( HWND hWndParent,
CWinThread *ptParentWinThread,
CString &rcsWinIpAddress,
int &rnWinPort,
BOOL fBroadcast,
int nSocketType,
long lEvent )
{
# ifdef LOG_ENABLE
ON_LOG_FUNCTION( va_string( " ---> Create( %s:%d )\n",
rcsWinIpAddress,
rnWinPort ));
# endif
bool fRc = false;
BOOL fRC;
BOOL fReuse = TRUE;
//
// Interface variables
//
m_hParentWnd = hWndParent;
m_ptParentWinThread = ptParentWinThread;
m_csWinIpAddress = rcsWinIpAddress;
m_nWinPort = rnWinPort;
m_fBroadcast = fBroadcast;
// Windows Order
CString csWinPrivateIpAddress;
UINT uWinPrivatePort;
fRC = Socket( nSocketType, lEvent, 0, PF_INET );
if ( fRC != FALSE )
{
//
// Setup the Socket Options
//
fRC = SetSockOpt( SO_REUSEADDR, &fReuse, sizeof( BOOL ), SOL_SOCKET );
// BOOL fNoDelay = TRUE;
// nRC = SetSockOpt( TCP_NODELAY, &fNoDelay, sizeof( BOOL ), IPPROTO_TCP );
if ( m_fBroadcast )
{
fRC = SetSockOpt( SO_BROADCAST, &m_fBroadcast, sizeof( BOOL ), SOL_SOCKET );
}
//
// Bind to the local adapter
//
fRC = Bind( m_nWinPort, m_csWinIpAddress );
//
// Now lets see what we end up with
//
if ( GetSockName( csWinPrivateIpAddress, uWinPrivatePort ) )
{
cheers
OldFart