Looking for an ECHO

sydbeam

New member
Joined
May 31, 2005
Messages
1
Programming Experience
Beginner
I am currently in the process of making a program to monitor the response of the server (PING). I Have a subroutine that executes under a button click. I thought that if I used the protocoltype.tcp and sent a string to the echo port (7) it would receive and send the same data back? Is this correct? If I change the port to 21 (FTP) I believe it actually makes a connection, with 7 it says the target machine actively refused it. My subroutine is shown below. I appreciate any help! THANKS!
Dim ipHostInfo As IPHostEntry = Dns.Resolve(TextBox4.Text)

Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)

Dim sock As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

Dim ipEnd As New IPEndPoint(ipAddress, TextBox7.Text) 'textbox7.text is the port integer

Try

sock.Connect(ipEnd)

Try

Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes(TextBox6.Text) 'textbox6 contains string to be Echoed

Dim bytesSent As Integer = sock.Send(msg)

Dim bytes(1024) As Byte

Dim bytesRec = sock.Receive(bytes)

Console.WriteLine("Echoed text = {0}", System.Text.Encoding.ASCII.GetString(bytes, 0, bytesRec))

sock.Shutdown(SocketShutdown.Both)

sock.Close()

Catch

MessageBox.Show("Connection with server has timed out", "Connection Error")

End Try

Catch

MessageBox.Show("No connection made because the target machine actively refused it.", "Connection Error")

End Try

 
Back
Top