DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Question about "disconnecing" TCP connections

  1. #1
    Join Date
    Aug 2008

    Question Question about "disconnecing" TCP connections

    This is my first post on this site, so please don't yell at me if this is in the wrong forum. So, real quick, a little about myself (If you prefer to jump straight to my question scroll down...):

    I am 28 years old and have been a teacher for 5 years. I have been programing for about 2 1/2 - 3 years now, and I have taught myself everything I know (with the help of sites like this and others). It started out as just some experimental things involving editing emulator games. Then it progressed into bigger projects like writing small applications for myself to use at school. As of late, I have been working with some people over at to mod Madden '08 into a Madden '09 (because EA isn't releasing one for the computer). And I am also working on an attendance program for my school (if I can learn more about actual server/client programming). This leads me to my question, actually...


    All of that is all fine and good, but I also have been working on a project of my own that started back 2 years ago with visual basic 6.0 and now I have completely upgraded into visual basic 9.0. The only issue is that part of the program gives me the local ip address, local port, remote ip address and remote port for everything that has that sort of connection to me at any given time (whether it be via internet, hosting a game, etc...). What I can't figure out is how to create a line(s) of code to disconnect certain connections.

    For example, let's say this is all in a list. One of the things in the list has these values:
    Local Address:
    Local Port: 6112
    Remote Address: 123.45.678.90
    Remote Port: 12345

    I want to "disconnect" that particular connection. Does that make sense? I figured that knowing that information should be good enough using things like sockets (maybe..) and stuff. The problem is that I have very little expertise using sockets. In visual basic 6, I just "stole" the code from some site online and it worked fine. In VB9, however, I have figured it out most of it on my own, and would like guidance for this last little part.

    Any help/guidance/direction to other sites that might help is GREATLY appreciated!


  2. #2
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    Welcome to DevX

    What is the VB6 code you are using for this? Perhaps "translating" that into VB.NET would be easier than trying to come up with something from scratch.

  3. #3
    Join Date
    Aug 2008
    Public Sub DisconnectTCP_Click(Index As Integer)
        Dim TcpTableRow As MIB_TCPROW
        Dim lngRetValue As Long
        TcpTableRow = TCPConnections(index).TCPRowNumber
        TcpTableRow.dwState = MIB_TCP_STATE_DELETE_TCB
        lngRetValue = SetTcpEntry(TcpTableRow)
    End Sub
    The "SetTcpEntry" functions comes from here:
        Public Declare Function SetTcpEntry Lib "iphlpapi.dll" (ByRef pTcpTable As MIB_TCPROW) As Long
    The TCPConnections array holds all the info from the TCPTable (remote Address, Local Address, Ports, etc...). I have already converted this over to VB9, but it does not seem to work correctly...

    Thanks for taking a look.


  4. #4
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    How are these declared:


  5. #5
    Join Date
    Aug 2008
    Quote Originally Posted by Hack
    How are these declared:

        Public Class MIB_TCPROW
            Public dwState As Integer
            Public dwLocalAddr As Integer
            Public dwLocalPort As Integer
            Public dwRemoteAddr As Integer
            Public dwRemotePort As Integer
        End Class
        Private Const MIB_TCP_STATE_CLOSED As Short = 1
        Private Const MIB_TCP_STATE_LISTEN As Short = 2
        Private Const MIB_TCP_STATE_SYN_SENT As Short = 3
        Private Const MIB_TCP_STATE_SYN_RCVD As Short = 4
        Private Const MIB_TCP_STATE_ESTAB As Short = 5
        Private Const MIB_TCP_STATE_FIN_WAIT1 As Short = 6
        Private Const MIB_TCP_STATE_FIN_WAIT2 As Short = 7
        Private Const MIB_TCP_STATE_CLOSE_WAIT As Short = 8
        Private Const MIB_TCP_STATE_CLOSING As Short = 9
        Private Const MIB_TCP_STATE_LAST_ACK As Short = 10
        Private Const MIB_TCP_STATE_TIME_WAIT As Short = 11
        Private Const MIB_TCP_STATE_DELETE_TCB As Short = 12

Similar Threads

  1. a question about TCP
    By nickiss in forum Java
    Replies: 0
    Last Post: 04-18-2005, 05:25 AM
  2. Display one record at a time!
    By ASP learner in forum ASP.NET
    Replies: 5
    Last Post: 10-08-2002, 07:17 PM
  3. Maximum TCP Socket Connections
    By Tom in forum Java
    Replies: 1
    Last Post: 02-03-2002, 03:23 AM
  4. Wireless Profoled TCP support
    By Mikael Nyberg in forum Mobile
    Replies: 0
    Last Post: 06-26-2001, 04:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center