simple connection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iwdu15

    #1

    simple connection

    hi, im new to creating connections to different computers in VB, so i tried a
    simple program to connect with a different computer with my program on it. I
    enter in the target computer's IP address, and try to connect to port 8080,
    but each time it says "Connection Activly Refused" so i have no idea whats
    wrong....heres my code

    Dim localIp As Net.IPAddress
    Dim connection As New Net.Sockets.Tcp Client
    Dim soc As Sockets.Socket

    Private Sub btnconnect_Clic k(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles btnconnect.Clic k

    Call connect()

    End Sub

    Sub connect()

    'Dim netstream As Net.Sockets.Net workStream
    Try
    connection.Conn ect(Me.TextBox1 .Text, 8080)
    MsgBox("Connect ion Made")
    Catch ex As Exception
    MsgBox(ex.Messa ge)
    End Try


    End Sub

    Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
    System.EventArg s) Handles MyBase.Load

    localIp = Dns.GetHostByNa me(Dns.GetHostN ame).AddressLis t.GetValue(0)

    End Sub

    Private Sub Form1_Closing(B yVal sender As Object, ByVal e As
    System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing

    localIp = Dns.GetHostByNa me(Dns.GetHostN ame).AddressLis t.GetValue(0)
    Dim listen As New Net.Sockets.Tcp Listener(localI p, 8080)
    connection.Clos e()
    listen.Stop()
    soc.Close()

    End Sub

    Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As
    System.EventArg s) Handles Timer1.Tick

    Dim listen As New Net.Sockets.Tcp Listener(localI p, 8080)
    Dim responsestring As String = "Connected"

    listen.Start()

    Try
    ' If soc.Connected = False Then
    soc = listen.AcceptSo cket
    If soc.Connected = True Then
    Dim sendBytes As [Byte]() =
    Encoding.ASCII. GetBytes(respon sestring)
    Dim i As Integer = soc.Send(sendBy tes)
    Timer1.Stop()
    End If
    'End If
    Catch ex As Exception
    MsgBox(ex.Messa ge)
    End Try

    listen.Stop()

    End Sub

    Private Sub btnlisten_Click (ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles btnlisten.Click

    Timer1.Start()

    End Sub

    any help would b awsome, thanks

    --
    -iwdu15
  • Thief_

    #2
    Re: simple connection

    Did u disable the firewalls on both computers as a test? Can you manually
    goto port 8080 on the other PC using the web browser? Where in your code did
    the error ocurr?

    --
    |
    +-- Thief_
    |

    "iwdu15" <iwdu15@discuss ions.microsoft. com> wrote in message
    news:154D93DC-4594-46CA-8560-5C0BECA7A259@mi crosoft.com...[color=blue]
    > hi, im new to creating connections to different computers in VB, so i[/color]
    tried a[color=blue]
    > simple program to connect with a different computer with my program on it.[/color]
    I[color=blue]
    > enter in the target computer's IP address, and try to connect to port[/color]
    8080,[color=blue]
    > but each time it says "Connection Activly Refused" so i have no idea whats
    > wrong....heres my code
    >
    > Dim localIp As Net.IPAddress
    > Dim connection As New Net.Sockets.Tcp Client
    > Dim soc As Sockets.Socket
    >
    > Private Sub btnconnect_Clic k(ByVal sender As System.Object, ByVal e As
    > System.EventArg s) Handles btnconnect.Clic k
    >
    > Call connect()
    >
    > End Sub
    >
    > Sub connect()
    >
    > 'Dim netstream As Net.Sockets.Net workStream
    > Try
    > connection.Conn ect(Me.TextBox1 .Text, 8080)
    > MsgBox("Connect ion Made")
    > Catch ex As Exception
    > MsgBox(ex.Messa ge)
    > End Try
    >
    >
    > End Sub
    >
    > Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
    > System.EventArg s) Handles MyBase.Load
    >
    > localIp =[/color]
    Dns.GetHostByNa me(Dns.GetHostN ame).AddressLis t.GetValue(0)[color=blue]
    >
    > End Sub
    >
    > Private Sub Form1_Closing(B yVal sender As Object, ByVal e As
    > System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
    >
    > localIp =[/color]
    Dns.GetHostByNa me(Dns.GetHostN ame).AddressLis t.GetValue(0)[color=blue]
    > Dim listen As New Net.Sockets.Tcp Listener(localI p, 8080)
    > connection.Clos e()
    > listen.Stop()
    > soc.Close()
    >
    > End Sub
    >
    > Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As
    > System.EventArg s) Handles Timer1.Tick
    >
    > Dim listen As New Net.Sockets.Tcp Listener(localI p, 8080)
    > Dim responsestring As String = "Connected"
    >
    > listen.Start()
    >
    > Try
    > ' If soc.Connected = False Then
    > soc = listen.AcceptSo cket
    > If soc.Connected = True Then
    > Dim sendBytes As [Byte]() =
    > Encoding.ASCII. GetBytes(respon sestring)
    > Dim i As Integer = soc.Send(sendBy tes)
    > Timer1.Stop()
    > End If
    > 'End If
    > Catch ex As Exception
    > MsgBox(ex.Messa ge)
    > End Try
    >
    > listen.Stop()
    >
    > End Sub
    >
    > Private Sub btnlisten_Click (ByVal sender As System.Object, ByVal e As
    > System.EventArg s) Handles btnlisten.Click
    >
    > Timer1.Start()
    >
    > End Sub
    >
    > any help would b awsome, thanks
    >
    > --
    > -iwdu15[/color]


    Comment

    • iwdu15

      #3
      Re: simple connection

      it appears on
      connection.Conn ect(Me.TextBox1 .Text, 8080)
      and the textbox contains an IP address

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: simple connection

        Iwdu15

        The kind of programs you are making are not simple.

        It are hacker style programs for which the most patches are given the last
        years on all kind of operating systems.

        Even if you succeed than it can be that you have problems tomorrow which
        where not yesterday because the port is closed by default or only assigned
        for by instance webbrowser request and replies.

        I hope this helps,

        Cor



        Comment

        • iwdu15

          #5
          Re: simple connection

          lol dont take this in the wrong way, i was by no means trying to create a
          hacker program, i was just trying to produce a, relativly, simple program to
          communicate with text, like a messeneger program. for instance when i attempt
          to connect to the other program, it would come up with i dialog box asking if
          they would like to connect or not, but i see this is getting more complex
          then i ever imagined

          Comment

          Working...