simple connection

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
 
T

Thief_

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?
 
G

Guest

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

Cor Ligthert [MVP]

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top