Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 7th, 2004, 12:36 PM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Derive TcpClient

Hi there

I try to have a specialized TcpClient. Therefore MyTcpClient derives from TcpClient. Now, i thougt the following is possible:

MyTcpClient client = (MyTcpClient) listener.AcceptTcpClient();

But the cast fails. Any idea why or a way to go around the problem?

Thank and cheers
Simon

Visit: http://pubwww.fhzh.ch/~sgysi
 
Old October 8th, 2004, 05:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

What error do you get, syntax-wise your code is correct.
 
Old October 8th, 2004, 11:02 AM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Compiles, but throws a invalid vast exception.

Simon

 
Old October 10th, 2004, 12:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

I tried it and found the same problem, although you can use classes derived from TcpClient on the client side.
 
Old October 11th, 2004, 06:18 PM
Kep Kep is offline
Authorized User
 
Join Date: Aug 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The only way you can get this to work is to use AcceptSocket().

try...
Code:
MyTcpClient client = new MyTcpClient(listener.AcceptSocket());
This should do what you need.

Kep.
 
Old October 11th, 2004, 11:01 PM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank all!
Simon






Similar Threads
Thread Thread Starter Forum Replies Last Post
can we able to derive a script from mdb mrleokarthik Pro VB 6 0 November 28th, 2003 08:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.