G
Guest
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.TcpClient
Dim soc As Sockets.Socket
Private Sub btnconnect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnconnect.Click
Call connect()
End Sub
Sub connect()
'Dim netstream As Net.Sockets.NetworkStream
Try
connection.Connect(Me.TextBox1.Text, 8080)
MsgBox("Connection Made")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
localIp = Dns.GetHostByName(Dns.GetHostName).AddressList.GetValue(0)
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
localIp = Dns.GetHostByName(Dns.GetHostName).AddressList.GetValue(0)
Dim listen As New Net.Sockets.TcpListener(localIp, 8080)
connection.Close()
listen.Stop()
soc.Close()
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim listen As New Net.Sockets.TcpListener(localIp, 8080)
Dim responsestring As String = "Connected"
listen.Start()
Try
' If soc.Connected = False Then
soc = listen.AcceptSocket
If soc.Connected = True Then
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(responsestring)
Dim i As Integer = soc.Send(sendBytes)
Timer1.Stop()
End If
'End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
listen.Stop()
End Sub
Private Sub btnlisten_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnlisten.Click
Timer1.Start()
End Sub
any help would b awsome, thanks
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.TcpClient
Dim soc As Sockets.Socket
Private Sub btnconnect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnconnect.Click
Call connect()
End Sub
Sub connect()
'Dim netstream As Net.Sockets.NetworkStream
Try
connection.Connect(Me.TextBox1.Text, 8080)
MsgBox("Connection Made")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
localIp = Dns.GetHostByName(Dns.GetHostName).AddressList.GetValue(0)
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
localIp = Dns.GetHostByName(Dns.GetHostName).AddressList.GetValue(0)
Dim listen As New Net.Sockets.TcpListener(localIp, 8080)
connection.Close()
listen.Stop()
soc.Close()
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim listen As New Net.Sockets.TcpListener(localIp, 8080)
Dim responsestring As String = "Connected"
listen.Start()
Try
' If soc.Connected = False Then
soc = listen.AcceptSocket
If soc.Connected = True Then
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(responsestring)
Dim i As Integer = soc.Send(sendBytes)
Timer1.Stop()
End If
'End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
listen.Stop()
End Sub
Private Sub btnlisten_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnlisten.Click
Timer1.Start()
End Sub
any help would b awsome, thanks