473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

connection acicly refused?

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\CurrentControl Set\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
Nov 21 '05 #1
9 1321
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" <iw****@discussions.microsoft.com> wrote in message
news:2B**********************************@microsof t.com...
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\CurrentControl Set\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
Nov 21 '05 #2
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
Nov 21 '05 #3
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
Nov 21 '05 #4
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
Nov 21 '05 #5
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.
Nov 21 '05 #6
lol sorry but im a noob at this stuff, not programming but connections,
internet protocols etc, wats "telnet", "smtp", and "iis"? thanks
Nov 21 '05 #7
"iwdu15" <iw****@discussions.microsoft.com> сообщил/сообщила в новостях
следующее: news:64**********************************@microsof t.com...
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.

Nov 21 '05 #8
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
Nov 21 '05 #9
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).Add ressList(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
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alex Hunsley | last post by:
I am using the smtp module to send emails via a local SMTP server on our network. I am failing with "connection refused" error, even though we definitely have an smtp server running on port 25! ...
8
by: Josh Close | last post by:
I'm using the smtplib module and I keep getting this error: (111, 'Connection refused') What could be causing this? I've tried it from a different computer and it seems to work, but not from this...
0
by: Sylvain Thenault | last post by:
Hi ! I got a connection refused when I try to upload a package using "python setup.py register". However login using the web interface works well. Does anyone has the same problem or is it a...
1
by: niceyama | last post by:
Dear c.l.p, I have recently been doing the tutorial of Python and everything is well, i'm upto the pass section. Anyway, when I try to launch idle now I get the error message: Socket Error:...
8
by: hufaunder | last post by:
I have a website that consumes a webservice. Both of them are in the Default Website folder. I can execute the service without any problem when I go to the test page http://localhost/Service.asmx....
8
by: trullock | last post by:
Hi, Is there a way to launch an remote desktop connection to a specified server/username from c#? If there's a way to send the password too that would be useful, but i'm not so interested in...
5
by: OJ | last post by:
Hi, I am at a loss here, I have a c# asp.net website which connects to a remote SQL Server 2000 db via a connection string. If I set the website up in the filesystem and use the inbuilt cassini...
9
by: rekabuk | last post by:
Hi folks, I'm having problems running a perl script that uses LWP. I'm trying to run webcal_cmd.pl which is part of WebCalendar by http://www.ma.utexas.edu/webcalendar/ When I run the script...
0
by: lesmith | last post by:
db2 governor failing with connection refused -------------------------------------------------------------------------------- We are trying to test using the db2 governor (udb v8) and get a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.