8 Replies - 2045 Views - Last Post: 23 September 2010 - 08:32 PM Rate Topic: -----

#1 SexySquirrel   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 97
  • Joined: 30-August 09

P2P Connection Problem

Posted 14 September 2010 - 09:54 PM

Hey, guys I just can't seem to establish a connection between my two P2P applications over the internet(LAN works perfectly fine). I have tried the following.
- Disabling Firewall
- Changing Port
The only way I can establish a connection is if I'm connecting to the same computer using the universal IP or the local.
Does anyone have a fix for this? Oh and here is the error that I receive when trying to connect over the internet:
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 255.255.255.255:8787
   at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)
   at P2P_Client.Form1.Msgtxt_KeyDown(Object sender, KeyEventArgs e) in C:\Users\Administrator\Documents\Visual Studio 2008\VB Projects\P2P-Client\P2P-Client\Form1.vb:line 32


Is This A Good Question/Topic? 0
  • +

Replies To: P2P Connection Problem

#2 Goethals   User is offline

  • D.I.C Head

Reputation: 25
  • View blog
  • Posts: 145
  • Joined: 14-April 09

Re: P2P Connection Problem

Posted 14 September 2010 - 11:47 PM

Your receiving device is not listening on that port right now.
Is the server app running on the receiving device?
Was This Post Helpful? 0
  • +
  • -

#3 SexySquirrel   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 97
  • Joined: 30-August 09

Re: P2P Connection Problem

Posted 15 September 2010 - 06:19 PM

Yes i make sure the "server" application is listening, I try both applications on the same machine before trying to establish the connection on two different machines.
Was This Post Helpful? 0
  • +
  • -

#4 Goethals   User is offline

  • D.I.C Head

Reputation: 25
  • View blog
  • Posts: 145
  • Joined: 14-April 09

Re: P2P Connection Problem

Posted 15 September 2010 - 11:52 PM

Could we please see the code where you're establishing a connection,
and the code when you receive an incomming connection?

Also have you tried to ping to your target device?
If you can't ping its a network problem. (Firewall?)

This post has been edited by Goethals: 15 September 2010 - 11:53 PM

Was This Post Helpful? 0
  • +
  • -

#5 SexySquirrel   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 97
  • Joined: 30-August 09

Re: P2P Connection Problem

Posted 16 September 2010 - 05:33 PM

Yeah, first I'll post Server then Client. I'll also try to ping my target and I'll get back to you on that.

P2P Server

Imports System.Net.Sockets
Imports System.Threading
Imports System.IO
Public Class Form1
#Region "Declarations"
    Dim Listener As New TcpListener(8787)
    Dim Client As New TcpClient
    Dim Message As String = ""
    Public Port As String
    Public strIPAddress As String
    Public strHostName As String
#End Region
#Region "FormLoad"
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ListThread As New Thread(New ThreadStart(AddressOf Listening))
        ListThread.Start()
        strHostName = System.Net.Dns.GetHostName()
        strIPAddress = System.Net.Dns.Resolve(strHostName).AddressList(0).ToString()
        NetworkIPLabel.Text = strIPAddress
        HostNameLabel.Text = strHostName
        Dim WC As New System.Net.WebClient
        IPv4AddressLabel.Text = System.Text.Encoding.ASCII.GetString((WC.DownloadData("http://whatismyip.com/automation/n09230945.asp")))
        WC.Dispose()
    End Sub
#End Region
#Region "Private Sub Listening()"
    Private Sub Listening()
        Listener.Start()
    End Sub
#End Region
#Region "Timer1_Tick//Listener"
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Listener.Pending = True Then
            Message = ""
            Client = Listener.AcceptTcpClient()
            Dim Reader As New StreamReader(Client.GetStream())
            While Reader.Peek > 0
                Message = Message & Convert.ToChar(Reader.Read()).ToString
            End While
            MsgBox(Message)
        End If
    End Sub
#End Region
#Region "FormClosing//Event-Listener.Stop()"
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Listener.Stop()
    End Sub
#End Region
#Region "StartListeningBtn_Click"
    Private Sub StartListeningBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartListeningBtn.Click
        Listener.Start()
        Timer1.Enabled = True
        InitiatedTimeLabel.Text = Date.Now
        IsListeningLabel.Text = "Listening"
        StartListeningBtn.Enabled = False
        StopListeningBtn.Enabled = True
    End Sub
#End Region
#Region "StopListeneningBtn_Click"
    Private Sub StopListeningBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopListeningBtn.Click
        Listener.Stop()
        Timer1.Enabled = False
        IsListeningLabel.Text = "Not Listening"
        StartListeningBtn.Enabled = True
        StopListeningBtn.Enabled = False
    End Sub
#End Region
End Class


P2P Client

Imports System.Net.Sockets
Imports System.Threading
Imports System.IO
Public Class Form1
#Region "Declarations"
    Dim Client As New TcpClient
    Dim Message As String = ""
    Public strIPAddress As String
    Public strHostName As String
#End Region
#Region "Form1_Load"
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        strHostName = System.Net.Dns.GetHostName()
        strIPAddress = System.Net.Dns.Resolve(strHostName).AddressList(0).ToString()
        NetworkIPLabel.Text = strIPAddress
        Dim WC As New System.Net.WebClient
        IPv4AddressLabel.Text = System.Text.Encoding.ASCII.GetString((WC.DownloadData("http://whatismyip.com/automation/n09230945.asp")))
        WC.Dispose()
        ServerIPAddresstxt.Text = NetworkIPLabel.Text
        HostNameLabel.Text = strHostName
        Try
            ServerIPAddresstxt.Text = My.Settings.IP
        Catch ex As Exception
        End Try
        Try
            NumericUpDown1.Value = My.Settings.Port
        Catch ex As Exception
        End Try
    End Sub
#End Region
#Region "Msgtxt_KeyDown//Send Message"
    Private Sub Msgtxt_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Msgtxt.KeyDown
        If e.KeyCode = Keys.Enter Then
            Try
                Client = New TcpClient(ServerIPAddresstxt.Text, 8787)
                Dim Writer As New StreamWriter(Client.GetStream())
                Writer.Write(Msgtxt.Text)
                Writer.Flush()
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub
#End Region
#Region "ConnectToServer"
    Private Sub ServerIPAddresstxt_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ServerIPAddresstxt.KeyDown
        If e.KeyCode = Keys.Enter Then
            Try
                Client = New TcpClient(ServerIPAddresstxt.Text, NumericUpDown1.Value)
                Dim Writer As New StreamWriter(Client.GetStream())
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub
#End Region

Was This Post Helpful? 0
  • +
  • -

#6 SexySquirrel   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 97
  • Joined: 30-August 09

Re: P2P Connection Problem

Posted 18 September 2010 - 10:51 AM

I was able to ping my target so I guess it isn't the firewall, what else can be the problem?
Was This Post Helpful? 0
  • +
  • -

#7 SexySquirrel   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 97
  • Joined: 30-August 09

Re: P2P Connection Problem

Posted 18 September 2010 - 10:45 PM

Goethals, do you know what the problem is, anyone? Can anyone help me establish a connection over the internet, I need it to send and receive messages like an IM.
Was This Post Helpful? 0
  • +
  • -

#8 Hypermx   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 06-August 09

Re: P2P Connection Problem

Posted 20 September 2010 - 03:49 PM

Are you sure you port forwarded correctly? Try using http://canyouseeme.org/ to see if 8787 is open.
Was This Post Helpful? 0
  • +
  • -

#9 SexySquirrel   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 97
  • Joined: 30-August 09

Re: P2P Connection Problem

Posted 23 September 2010 - 08:32 PM

It turns out the website could not see me:( lol what can I do to fix this?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1