www.pudn.com > lphant-v1.00-src.zip > Remoting.cs
#region Copyright (c)2003 Juanjo < http://lphant.sourceforge.net >
/*
* This file is part of eLePhant
* Copyright (C)2003 Juanjo < j_u_a_n_j_o@users.sourceforge.net / http://lphant.sourceforge.net >
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#endregion
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Messaging;
using eLePhant.eDonkey;
//dos clases para obtener acceso a las preferecias de la aplicacion.
//y todo por no existir todavia el formulario principal.
using eLePhant.Classes;
using System.Windows.Forms;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Collections;
using System.IO;
using System.Net;
using ICSharpCode.SharpZipLib;
namespace eLePhant.Client
{
///
/// Descripción breve de edonkeyCRemoto.
///
public class CedonkeyCRemoto
{
private TcpClientChannel m_lPhantChannel;
private IPAddress m_ip;
public IPAddress ip(){ return m_ip;}
private int m_puertos=4670;
public int puertos(){ return m_puertos;}
private string m_url;
public string url(){ return m_url;}
private int m_puertor;
public int puertor(){ return m_puertor;}
public CInterfaceGateway interfazremota;
private Hashtable props ;
private IClientChannelSinkProvider provider;
public CedonkeyCRemoto()
{
props = new Hashtable();
props.Add("name","eLePhantClient");
props.Add("priority","10");
props.Add("port",0);
#if (!COMPRESSION)
props.Add("supressChannelData",true);
props.Add("useIpAddress",true);
props.Add("rejectRemoteRequests",false);
provider = new BinaryClientFormatterSinkProvider();
#else
//iniciacion
Hashtable propsinks = new Hashtable();
propsinks.Add("includeVersions",true);
Hashtable datasinks = new Hashtable();
//2ª Opcion
provider = new eLePhantClientSinkProvider(propsinks,datasinks);
#endif
}
~CedonkeyCRemoto()
{
RemotingConfiguration.Configure(null);
ChannelServices.UnregisterChannel(m_lPhantChannel);
}
public void DisConnect()
{
try
{
RemotingConfiguration.Configure(null);
ChannelServices.UnregisterChannel(m_lPhantChannel);
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
public bool Connect(string IP,string clave,int puertor)
{
m_ip = IPAddress.Parse(IP);
if (puertor!=0)
this.m_puertos=puertor;
this.m_url="tcp://" + IP + ":" + this.m_puertos + "/InterfazRemota";
this.m_puertor=puertor;
System.Security.Cryptography.MD5 cripto=System.Security.Cryptography.MD5.Create();
bool valor=false;
try
{
m_lPhantChannel = new TcpClientChannel(props, provider);
ChannelServices.RegisterChannel(m_lPhantChannel);
}
catch
{
DisConnect();
if (m_lPhantChannel!=null)
ChannelServices.RegisterChannel(m_lPhantChannel);
else
m_lPhantChannel = new TcpClientChannel(props, provider);
}
interfazremota = (CInterfaceGateway) Activator.GetObject(typeof(eLePhant.eDonkey.CInterfaceGateway),
this.m_url);
if (interfazremota == null)
Debug.Write("No se pudo encontrar el servidor");
else
{
try
{
valor = interfazremota.CheckPw( clave );
}
catch
{
Debug.Write("\nNo se pudo encontrar el servidor\n");
}
}
return valor;
}
public bool Connect(string IP,int puertol,string clave,int puertor)
{
m_ip = IPAddress.Parse(IP);
if (puertor!=0)
this.m_puertos=puertor;
this.m_url="tcp://" + IP + ":" + this.m_puertos + "/InterfazRemota";
this.m_puertor=puertor;
System.Security.Cryptography.MD5 cripto=System.Security.Cryptography.MD5.Create();
bool valor=false;
try
{
m_lPhantChannel = new TcpClientChannel(props, provider);
ChannelServices.RegisterChannel(m_lPhantChannel);
}
catch
{
DisConnect();
if (m_lPhantChannel!=null)
ChannelServices.RegisterChannel(m_lPhantChannel);
else
m_lPhantChannel = new TcpClientChannel(props, provider);
}
interfazremota = (CInterfaceGateway) Activator.GetObject(typeof(eLePhant.eDonkey.CInterfaceGateway),
this.m_url);
if (interfazremota == null)
Debug.Write("No se pudo encontrar el servidor");
else
{
//c = new byte[clave.Length];
//for (int i=0;i