By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,795 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,795 IT Pros & Developers. It's quick & easy.

simple connection

P: n/a
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.Get Value(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.Get Value(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

--
-iwdu15
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <iw****@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.com...
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.Get Value(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.Get Value(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

--
-iwdu15

Nov 21 '05 #2

P: n/a
it appears on
connection.Connect(Me.TextBox1.Text, 8080)
and the textbox contains an IP address
Nov 21 '05 #3

P: n/a
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

Nov 21 '05 #4

P: n/a
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
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.