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
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
Comment