PC Review


Reply
Thread Tools Rate Thread

connection acicly refused?

 
 
=?Utf-8?B?aXdkdTE1?=
Guest
Posts: n/a
 
      20th Aug 2005
hi, im trying to make a simple connection with a friend using port 8080, but
for some reason the other computer always refuses connection, even if they
disable their firewall....heres my code, any help would b awsome

Dim localIp As Net.IPAddress
Dim connection As New Net.Sockets.TcpClient
Dim reg As Registry
''this is to find the local ip, i dont kno if it works, so if anyone could
help with that ''too
Dim rk As RegistryKey =
reg.LocalMachine.OpenSubKey("System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{06ECB9C5-1DF8-481F-AB69-3C181F4A7}")

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Call connect()

End Sub

Sub connect()

Dim netstream As Net.Sockets.NetworkStream

Try
connection.Connect(IP TO SEND GOES HERE, 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

Try
localIp = localIp.Parse(rk.GetValue("DhcpIPAddres", ""))
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim listen As New Net.Sockets.TcpListener(localIp, 8080)
listen.Start()


End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

localIp = localIp.Parse(rk.GetValue("DhcpIPAddres", ""))
Dim listen As New Net.Sockets.TcpListener(localIp, 8080)
connection.Close()
listen.Stop()

End Sub
 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      21st Aug 2005
Hi,

I would have your friend get his ip address manually and try to
ping him. You can get your ip here.

http://www.showmyip.com/

Ken
------------------------

"iwdu15" <(E-Mail Removed)> wrote in message
news:2B663619-447D-4D43-9F37-(E-Mail Removed)...
hi, im trying to make a simple connection with a friend using port 8080, but
for some reason the other computer always refuses connection, even if they
disable their firewall....heres my code, any help would b awsome

Dim localIp As Net.IPAddress
Dim connection As New Net.Sockets.TcpClient
Dim reg As Registry
''this is to find the local ip, i dont kno if it works, so if anyone could
help with that ''too
Dim rk As RegistryKey =
reg.LocalMachine.OpenSubKey("System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{06ECB9C5-1DF8-481F-AB69-3C181F4A7}")

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Call connect()

End Sub

Sub connect()

Dim netstream As Net.Sockets.NetworkStream

Try
connection.Connect(IP TO SEND GOES HERE, 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

Try
localIp = localIp.Parse(rk.GetValue("DhcpIPAddres", ""))
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim listen As New Net.Sockets.TcpListener(localIp, 8080)
listen.Start()


End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

localIp = localIp.Parse(rk.GetValue("DhcpIPAddres", ""))
Dim listen As New Net.Sockets.TcpListener(localIp, 8080)
connection.Close()
listen.Stop()

End Sub


 
Reply With Quote
 
=?Utf-8?B?aXdkdTE1?=
Guest
Posts: n/a
 
      21st Aug 2005
getting their IP address isnt the problem....i think i found a registry key
which saves it in there, but i wanted to kno y the code i showed isnt
connecting to the other user
 
Reply With Quote
 
Dragon
Guest
Posts: n/a
 
      21st Aug 2005
Hi,

You have to call the TcpListener.AcceptTCPClient() method to obtain a
TCPClient, which you will use for communication:

~
> Dim listen As New Net.Sockets.TcpListener(localIp, 8080)
> listen.Start()

Dim MyAcceptedClient as Net.Sockets.TcpClient = listen.AcceptTcpClient()
~

I hope this helps

Roman


 
Reply With Quote
 
=?Utf-8?B?aXdkdTE1?=
Guest
Posts: n/a
 
      21st Aug 2005
hi, yes i tried that next, in a timer event i checked the port to see if
there was a connection available, and the computer i was trying to connect to
got an error saying no reference to inmstance of an object
 
Reply With Quote
 
Dragon
Guest
Posts: n/a
 
      22nd Aug 2005
I'm not sure what your error is about, so I'd recommend you to test your
code this way:

1. To test your listening code, start your listening program, and try to
telnet it. If connection is established, then listening part is doing
fine.
2. To test your connecting code, open your connecting program, start
SMTP server from IIS, and try to connect to it.

Thus, you can determine what code is invalid.


 
Reply With Quote
 
=?Utf-8?B?aXdkdTE1?=
Guest
Posts: n/a
 
      22nd Aug 2005
lol sorry but im a noob at this stuff, not programming but connections,
internet protocols etc, wats "telnet", "smtp", and "iis"? thanks
 
Reply With Quote
 
Dragon
Guest
Posts: n/a
 
      22nd Aug 2005
"iwdu15" <(E-Mail Removed)> сообщил/сообщила в новостях
следующее: news:64A5DEC2-3C39-46F8-A491-(E-Mail Removed)...
> lol sorry but im a noob at this stuff, not programming but

connections,
> internet protocols etc, wats "telnet", "smtp", and "iis"? thanks


telnet - %windir%\system32\telnet.exe - command line tool, you can use
it to connect to some server (type telnet /? for usage instructions)
SMTP ≈ simple mail transfer protocol. You use it when you send e-mail
via e-mail client.
IIS ≈ internet information services, Windows built in server. If you
have VS .NET installed, you probably got this one too.



 
Reply With Quote
 
=?Utf-8?B?aXdkdTE1?=
Guest
Posts: n/a
 
      22nd Aug 2005
ok i used the telnet thing and it wouldnt connect to my program, so thats the
problem i think...thats for ur help but would u happen to kno y it doesnt
work? heres my code to listen, it listens in a timer tick every 100 of a
second, heres the code:

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

Try
Dim listen As New Net.Sockets.TcpListener(localIp, 8080)
listen.Start()
If listen.Pending Then
listen.AcceptTcpClient()
listen.AcceptSocket()
Else
listen.Stop()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub
 
Reply With Quote
 
Dragon
Guest
Posts: n/a
 
      23rd Aug 2005
Okay, beginning to explain...

> Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Timer1.Tick
>
> Try
> Dim listen As New Net.Sockets.TcpListener(localIp, 8080)

Why do you create new listener each time? Wouldn't it be more effective
to create one and forever?
> listen.Start()

If listen.Pending Then
Immediately after starting you check for incoming connections. I doubt
that some program can connect during this ^small^ amount of time.
> listen.AcceptTcpClient()

TcpClient you accepted goes into nowhere. I wonder how will you close
it?
> listen.AcceptSocket()

For some curious reason, you decided to accept another connection, this
time as a socket. However, this socket goes into neverhood too.
BTW, you get listener, that continues to listen and you can't stop it
because listen variable goes out of scope here; so it will listen until
garbage collection.
> Else
> listen.Stop()
> End If
> Catch ex As Exception
> MsgBox(ex.Message)
> End Try
>
> End Sub


Whew... Look below for the sample I made that works (at least at my
machine). I'm sure you can adapt it for your needs.

' --- SimpleListener.vb ---
' --- Waits for single connection on port 8080, sends a simple text
string and disconnects ---
' --- Compile with vbc /r:System.dll SimpleListener.vb ---
Option Strict On
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports Microsoft.VisualBasic
Module SimpleListener
Public Function Main(args() as String) as Integer
Dim TCPL as New
TcpListener(Dns.GetHostByName(Dns.GetHostName).AddressList(0), 8080)
TCPL.Start()
Dim TCPC as TcpClient = TCPL.AcceptTcpClient()
TCPL.Stop()
TCPC.GetStream().Write(New Byte() {Asc("Y"c),Asc("E"c),Asc("S"c)},0,3)
TCPC.Close
Return 0
End Function
End Module


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection refused? Kyle Turner Windows Vista Mail 3 18th Sep 2007 01:45 AM
(111) Connection refused =?Utf-8?B?WWVhZ2VyaG9vZA==?= Windows XP General 2 23rd Jul 2007 03:26 PM
Connection Refused? =?Utf-8?B?bGlxdWlkeA==?= Windows XP General 5 8th Dec 2005 01:10 AM
Re: Connection refused PA Bear Windows XP Internet Explorer 0 22nd Mar 2005 12:44 AM
Refused Connection on XP Pro =?Utf-8?B?Sm9uUg==?= Windows XP Work Remotely 1 4th Mar 2005 04:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:11 PM.