Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Socket = TCPClient.Client

Posted on 2005-05-09
6
Medium Priority
?
496 Views
Last Modified: 2012-06-27
Is there a way to get the System.Net.Socket from a TCPClient ? in the help it says that the TCPClient class has a protected property "client" that gets "or sets?" the underlying socket. The TCPClient that I have delcared does not give me the following option....
(Assuming TCPClient is already in action)

Dim Sock as Socket
sock = Tcpclient.client

How would I accomplish this?

0
Comment
Question by:addicktz
  • 4
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
ankur313 earned 2000 total points
ID: 13965729
The Client property is not accessible in this context because it is protected.

To use this property you will have to create a class which Derives from System.Net.Sockets.TcpClient.

Here's an example:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetsocketstcpclientclassclienttopic.asp

0
 
LVL 1

Author Comment

by:addicktz
ID: 13965803
with that example, i am still not sure how to return the socket, how would i return a value using that class?
0
 
LVL 1

Expert Comment

by:ankur313
ID: 13965982
Inside that class you could create a public variable of type Socket. You can then assign this variable with Me.client. Then write a SUB to return the variable.

If u r having trouble using the class let me know.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:addicktz
ID: 13970366
ya, im lost
0
 
LVL 1

Author Comment

by:addicktz
ID: 14052971
this is what I was able to come up with, but It is not letting me use the active property, and I dont know if I am doing this right at all, its not working thats for sure =]


    Public Class gets
        Inherits TcpClient
        Public c As Object
        Public Sub New(ByVal clint As TcpClient)
            c = clint
        End Sub 'New

        Public Function gethandle() As String

            'Uses the protected 'Active' property  belonging to the TcpClient base class
            'to determine if a connection is established.
            If c.Active = True Then
                ' Calls the protected 'Client' property belonging to the TcpClient base class.
                Dim s As Socket = c.Client
                'Uses the Socket returned by Client to set an option that is not available using TcpClient.
                gethandle = s.Handle.ToString
            End If
            'To free all resources, calls protected virtual method Dispose belonging to the TcpClient base class.
            Me.Dispose(True)
            GC.SuppressFinalize(Me)
        End Function 'UsingProtectedMethods
    End Class 'MyTcpClientDerivedClass
0
 
LVL 1

Author Comment

by:addicktz
ID: 14053001
when it says underlying socket....does that mean the active socket in that class? what if there is two?

should I be putting that code in the class with the tcpclient?
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Screencast - Getting to Know the Pipeline
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question