Re: wodVPN For 1 Server - N Client Scenario - WeOnlyDo Discussion board

Re: wodVPN For 1 Server - N Client Scenario (General questions)

by wodDamir, Saturday, October 11, 2008, 17:58 (5888 days ago) @ wodDamir

[code]namespace WindowsApplication4
{
public partial class Form1 : Form
{
//This is where i made declarations
private WODVPNCOMLib.wodVPNComClass VpnServer1;
private WODVPNCOMLib.wodVPNComClass VpnClient1, VpnClient2;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//Initialize components
VpnServer1 = new WODVPNCOMLib.wodVPNComClass();
VpnClient1 = new WODVPNCOMLib.wodVPNComClass();
VpnClient2 = new WODVPNCOMLib.wodVPNComClass();

//assign settings, and start listening
VpnClient1 = new WODVPNCOMLib.wodVPNComClass();
VpnClient1.Connected += new WODVPNCOMLib._IwodVPNComEvents_ConnectedEventHandler

(VpnClient1_Connected);
VpnClient1.SearchDone += new WODVPNCOMLib._IwodVPNComEvents_SearchDoneEventHandler

(VpnClient1_SearchDone);
VpnClient1.MyID = Server ;
VpnClient1.Password = anypass... ;
VpnClient1.Timeout = 15;
VpnClient1.Start(0);

VpnClient2 = new WODVPNCOMLib.wodVPNComClass();
VpnClient2.Connected += new WODVPNCOMLib._IwodVPNComEvents_ConnectedEventHandler

(VpnClient2_Connected);
VpnClient2.SearchDone += new WODVPNCOMLib._IwodVPNComEvents_SearchDoneEventHandler

(VpnClient2_SearchDone);
VpnClient2.MyID = Server ;
VpnClient2.Password = anypass... ;
VpnClient2.Timeout = 15;
VpnClient2.Start(0);

//Start mediator
VpnServer1.Mediator.Timeout = 1;
VpnServer1.Threads = true;
VpnServer1.MediatorConnected += new WODVPNCOMLib._IwodVPNComEvents_MediatorConnectedEventHandler

(VpnServer1_MediatorConnected);
VpnServer1.Mediator.Start(WODVPNCOMLib.SearchEnum.SrchUDPSingle,8000);
}
//When search is done, connect...
void VpnClient1_SearchDone(string IP, int Port, int ErrorCode, string ErrorText)
{
if (ErrorCode == 0)
{
VpnClient1.Connect(IP, Port);

}
else
{
Console.WriteLine(ErrorText);
}
}

void VpnClient2_SearchDone(string IP, int Port, int ErrorCode, string ErrorText)
{
if (ErrorCode == 0){
VpnClient2.Connect(IP, Port);}
else{
Console.WriteLine(ErrorText);}
}

//This part is where we detect the user connection, and decide which instance to use in order to connect peers
void VpnServer1_MediatorConnected(string IP, int Port, string FromID, string ToID, string Data, ref bool Allow)
{
try
{if (VpnClient1.State == WODVPNCOMLib.StatesEnum.Listening)
{
VpnClient1.Search(WODVPNCOMLib.SearchEnum.SrchUDPSingle, FromID, 127.0.0.1 , 8000, null);
}
else if (VpnClient1.State == WODVPNCOMLib.StatesEnum.Connected && VpnClient2.State == WODVPNCOMLib.StatesEnum.Listening)
{
VpnClient2.Search(WODVPNCOMLib.SearchEnum.SrchUDPSingle, FromID, 127.0.0.1 , 8000, null);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
//Just log the connection
void VpnClient1_Connected(string PeerID, string IP, int Port)
{
Console.WriteLine( Client1 connected with + PeerID + on + IP);
}

void VpnClient2_Connected(string PeerID, string IP, int Port)
{
Console.WriteLine( Client2 connected with + PeerID + on + IP);
}
}
}
[/code]


Complete thread: