Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27083

VS 2010 TCP Communication problem

$
0
0
I am trying to make a TCP communication over the Internet, it works just as it should on my internal network, though over the Internet it doesn't. I am testing the communication with a Windows Azure server and I get the following message when I try to reach the server:

Quote:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
This is my program, which runs on both machines

Code:

Imports System.Net
Imports System.IO
Public Class Form1
    Dim listener As Net.Sockets.TcpListener
    Dim listenthread As Threading.Thread
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load     
        listener = New Net.Sockets.TcpListener(Net.IPAddress.Any, 10)
        listener.Start()
        listenthread = New Threading.Thread(AddressOf DoListen)
        listenthread.IsBackground = True
        listenthread.Start()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        send(TextBox1.Text)
    End Sub

    Private Sub DoListen()
        Dim Reader As StreamReader
        Do
            Try
                Dim OtherEnd As Sockets.TcpClient = listener.AcceptTcpClient
                Reader = New StreamReader(OtherEnd.GetStream)
                MsgBox(Reader.ReadToEnd)
                Dim IPClient As IPEndPoint = OtherEnd.Client.RemoteEndPoint
                send(IPClient.Address.ToString)
            Catch ex As Exception

            End Try
        Loop
    End Sub

    Private Sub send(ByVal IP As String)
        Dim client As New Net.Sockets.TcpClient
        client.Connect(IP, 10)
        Dim Writer As New StreamWriter(client.GetStream)
        Writer.Write(TextBox2.Text)
        Writer.Close()
    End Sub
End Class


Viewing all articles
Browse latest Browse all 27083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>