I am using C# in .Net 1.1, and need to access the 'Client' Property of TcpClient, so I created a derived class to do this based upon the Microsoft Sample, located at:
The only problem is that in my main app, when I try to do the following, I get an Invalid Cast Exception:
[CODE=csharp]int PortNum = 10000;
TcpListener objTcpListen = new TcpListener(IPA ddress.Any,Port Num );
MyTcpClient objectMyTcpClie nt = this.objTcpList en.AcceptTcpCli ent(); <-- Generates the Invalid Cast Exception[/CODE]
Does anyone know how to deal with this issue?
There was a post on the Microsoft Public Newsgroup that posted the same question, except this user was using VB. Unfortunately he withdrew his question, so there was no answer. http://www.thescripts.com/forum/thread371494.html
*************** *************** **************
My TcpClient Derived Class
*************** *************** **************
[CODE=csharp]public class MyTcpClient : TcpClient
{
// Constructor for the derived class.
public MyTcpClient () : base()
{
}
public MyTcpClient (string pHostname, int pPort) : base(pHostname, pPort)
{
}
public MyTcpClient (System.Net.Soc kets.AddressFam ily pFamily) : base(pFamily)
{
}
public MyTcpClient (System.Net.IPE ndPoint pLocalEP) : base(pLocalEP)
{
}
public bool getActive
{
get
{
return this.Active;
}
}
public Socket getSocket
{
get
{
return this.Client;
}
}
}[/CODE]
The only problem is that in my main app, when I try to do the following, I get an Invalid Cast Exception:
[CODE=csharp]int PortNum = 10000;
TcpListener objTcpListen = new TcpListener(IPA ddress.Any,Port Num );
MyTcpClient objectMyTcpClie nt = this.objTcpList en.AcceptTcpCli ent(); <-- Generates the Invalid Cast Exception[/CODE]
Does anyone know how to deal with this issue?
There was a post on the Microsoft Public Newsgroup that posted the same question, except this user was using VB. Unfortunately he withdrew his question, so there was no answer. http://www.thescripts.com/forum/thread371494.html
*************** *************** **************
My TcpClient Derived Class
*************** *************** **************
[CODE=csharp]public class MyTcpClient : TcpClient
{
// Constructor for the derived class.
public MyTcpClient () : base()
{
}
public MyTcpClient (string pHostname, int pPort) : base(pHostname, pPort)
{
}
public MyTcpClient (System.Net.Soc kets.AddressFam ily pFamily) : base(pFamily)
{
}
public MyTcpClient (System.Net.IPE ndPoint pLocalEP) : base(pLocalEP)
{
}
public bool getActive
{
get
{
return this.Active;
}
}
public Socket getSocket
{
get
{
return this.Client;
}
}
}[/CODE]
Comment