Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
Imports System.Net.Sockets Imports System.net Imports System.Text Imports System.Net.DnsPermissionAttribute Imports System.Security.Permissions Public Class Form1 Const portNumber As Integer = 5679 Private tcpListener As New TcpListener(CType(Dns.Resolve("LMI111").AddressList(0), IPAddress), portNumber) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Listening must be on the same port that the client is connected on. '"Localhost" string is used when the client and the listener are on the same computer. 'If the listener is listening at a computer that is different from the client, then provide the host name of the computer 'where the listener is listening. 'Comment the previous line and uncomment the following line if you are using Visual Basic .NET (2003). 'Dim tcpListener As New TcpListener(portNumber) tcpListener.Start() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Console.WriteLine("TCP Server is up and waiting for Client connection...") Me.Label1.Text = "TCP Server is up and waiting for Client connection..." ''Accept the pending client connection and return a TcpClient for communication. Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient() ' Console.WriteLine("Connection accepted.") ' Get the data stream. Dim networkStream As NetworkStream = tcpClient.GetStream() ' Read the data stream into a byte array. Dim bytes(tcpClient.ReceiveBufferSize) As Byte networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize)) ' Return the data received from the client to the console. Dim clientdata As String = Encoding.ASCII.GetString(bytes) Me.Label1.Text = "Client sent: " + clientdata Dim responseString As String = "Successfully connected to TCP server." Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(responseString) networkStream.Write(sendBytes, 0, sendBytes.Length) 'Console.WriteLine(("Message Sent by TCP Server /> : " + responseString)) 'Close TcpListener and TcpClient. tcpClient.Close() tcpListener.Stop() ' Console.WriteLine("Exit") 'Console.ReadLine() End Sub End Class
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.