I am programming in VB.NET.
I would like to send a String or Integer from a VB.NET application to another VB.NET application on different computers.
I looked through some lessons, but all the tutorials work only on the local network, and I want it to work over the Internet.
This is my code for local connections:
Dim Listener As New TcpListener(34349) Dim Client As New TcpClient Dim Message As String = "" 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 End If End Sub Private Sub btnSend_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnsend.Click If txtName.Text = "" Or cmbAddress.Text = "" Then MessageBox.Show("All Fields must be Filled", _ "Error Sending Message", _ MessageBoxButtons.OK, _ MessageBoxIcon.Error) Else Try Client = New TcpClient(cmbAddress.Text, 34349) Dim Writer As New StreamWriter(Client.GetStream()) Writer.Write(txtName.Text & " Says: " & txtmessage.Text) Writer.Flush() RichTextBox1.Text += (txtName.Text & " Says: " & txtmessage.Text) + vbCrLf 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
txtmessage.text
is the string I want to send.
txtName.Text
is just the name of the sender
cmbAddress.text
is the IP address of the remote computer
How can I send data to another remote computer in VB.NET?
source share