Click here to Skip to main content
15,867,835 members

Comments by Michael Azzar (Top 30 by date)

Michael Azzar 27-May-15 10:34am View    
Thank you very much sir 😊 for. Your time ...
Michael Azzar 27-May-15 9:55am View    
Referring to router setting .I use cellular data( phone. ) to connect to the internet
Michael Azzar 27-May-15 8:15am View    
Hello Mr. Frankie
I hope you are fine
Wanted to tell you the outcome of the final test.
I've run my app on two PC connected to the internet.
But unfortunately l have encountered the same problem although I make an exception for the app in windows firewall
This is the. App code
You probably know the cause of the problem

Imports System.Net.Sockets
Imports System.Threading
Imports System.IO

Public Class Form1
Dim Listener As New TcpListener(65535)
Dim Client As New TcpClient
Dim Message As String = ""

Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
GC.Collect()
End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Timer1.Stop()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtmyIPAddress.Text = GetIPAddress()
Dim ListenerThread As New Thread(New ThreadStart(AddressOf Listening))
ListenerThread.Start()
Timer1.Start()
txtName.Focus()
End Sub
Private Sub Listening()
Listener.Start()
End Sub

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 > -1
Message = Message + Convert.ToChar(Reader.Read()).ToString
End While
RichTextBox1.ForeColor = Color.Black
RichTextBox1.Text += Message + vbCrLf
'Here you can enter anything you would like
'to happen when a message is received,
'For instance; Play a sound, Show a message Box, A Balloon Tip etc.
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If txtName.Text = "" Or cmbAddress.Text = "" Then
'Check to make sure that the user has entered
'a display name, and a client IP Address
'If Not, Show a Message Box
MessageBox.Show("UserName and IPAddress must be Filled", _
"Error Sending Message", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Try
Client = New TcpClient(cmbAddress.Text, 65535)

'Declare the Client as an IP Address.
'Must be in the Correct form. eg. 000.0.0.0
Dim Writer As New StreamWriter(Client.GetStream())
Writer.Write(txtName.Text & " Says: " & txtmessage.Text)
Writer.Flush()

'Write the Message in the stream
If Not txtmyIPAddress.Text.Trim = cmbAddress.Text.Trim Then
RichTextBox1.Text += (txtName.Text & " Says: " & txtmessage.Text) + vbCrLf
End If
txtmessage.Text = ""
Catch ex As Exception
Console.WriteLine(ex)
Dim Errorresult As String = ex.Message
MessageBox.Show(Errorresult & vbCrLf & vbCrLf & _
"Please Review Client Address", _
"Error Sending Message", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

End If
End Sub
Private Function GetIPAddress() As String
Dim oAddr As System.Net.IPAddress
Dim sAddr As String
With System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName())
oAddr = New System.Net.IPAddress(.AddressList(0).Address)
sAddr = oAddr.ToString
End With
GetIPAddress = sAddr
End Function
End
Michael Azzar 25-May-15 1:29am View    
Thank you Mr.Sergey for your links
I think that it will help me more
Thank you 😊 very much...
Michael Azzar 25-May-15 1:26am View    
My vote is 5
Thank you very much Mr. Frankie-C for your clear answer.
I think that the solution included in it.
But unfortunately I can't try it now, because I am on a business trip for a week. But I'm going to try it and give you feedback