TCP Socket class-VBForums
Results 1 to 9 of 9

Thread: TCP Socket class

  1. #1

    Thread Starter
    Member
    Join Date
    May 2003
    Posts
    58

    TCP Socket class

    Hopefully this class can be usefull for u guys...
    Attached Files Attached Files

  2. #2

    Thread Starter
    Member
    Join Date
    May 2003
    Posts
    58
    since it is posted under CodeBank - VISUAL BASIC .NET, so its clear that the class is written in VB.NET, however it still can be compiled as .NET component and be used in C++ or C# project.

    To clarify what the functionalities of the class are and how it can be implemented into ur application:
    ----------------------------------------------------------------------------------

    This class is made to have similar functionality with Winsock control in VB6. It provide the basic functions like Listen, Connect, Close, and also events like Connecting, Connected, DataArrival, IncomingConnection. However, it is not as complex as VB6 Winsock. Whoever has ever used VB6 Winsock control should have no problem using this class.

    This class may be freely distributed and be used in any application. The user may also modify the original code and extend the functionalities.

    To use the class just simply declare with WithEvents keyword. Declare one as client and another as server, they should reside in different applications or in the same one if required. Remember to declare an instance before using any of its members:


    Dim WithEvents cServer as clsTCPSocket
    Dim WithEvents cClient as clsTCPSocket


    'the server must listen to an avalaible port before the client can connect

    Private Sub btnListen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListen.Click
    cServer.Listen(100)
    End Sub


    'to connect just simple call the connect function with the same port number as specified by server.

    Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
    cClient.Connect("PCName", 100)
    End Sub



    Private Sub IncomingConnHandler() Handles cServer.IncomingConnection
    cServer.Accept()
    End Sub


    to send data just call SendData function, the DataArrival event will be invoked when the data received.

  3. #3
    Lively Member
    Join Date
    Jul 2004
    Posts
    102

    Re: TCP Socket class

    Any Chance of a sample app using this class as I cant get this to work.

  4. #4
    New Member
    Join Date
    Jun 2009
    Posts
    10

    Re: TCP Socket class

    You Beauty!!!
    This fixed most of my problems!! Works far better then SocketsClient.

  5. #5
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    970

    Re: TCP Socket class

    can you give a sample solution on how to use your class, am relly new in .net technologies
    Programming is all about good logic. Spend more time here


    (vHost for Apache) (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  6. #6
    New Member
    Join Date
    Jan 2012
    Posts
    2

    Re: TCP Socket class

    Can Somebody help me with this class? I need an example how to receive data... Any change to get help on this old post?

  7. #7
    Member
    Join Date
    Aug 2010
    Posts
    35

    Re: TCP Socket class

    i got some problem with dataArraival of this class. can you plz tell me how can get incomming bytes properly as string

  8. #8
    New Member
    Join Date
    Oct 2012
    Posts
    5

    Re: TCP Socket class

    can u please add index for every connection like this
    Code:
    Public Sub client_Connected(ByVal Index As Integer) Handles client.Connected
    
    End Sub
    to control between multiple connections ??
    thanks for this amazing class

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    4,999

    Re: TCP Socket class

    Quote Originally Posted by atef201080 View Post
    can u please add index for every connection like this
    Code:
    Public Sub client_Connected(ByVal Index As Integer) Handles client.Connected
    
    End Sub
    to control between multiple connections ??
    thanks for this amazing class
    lol that is such a VB6 question. I haven't used this class but if the author wrote the events properly, I'd expect the event handler to have a sender argument which you can use to identify specific sockets.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.