You are creating a Microsoft Windows Mobilebased application.
The application connects to a remote server named www.contoso.com on port 80.
You need to retrieve data from the remote server by using the TcpClient class.
Which code segment should you use?
Answer(s)
- Dim tcpClient As New TcpClient()Dim netStream As NetworkStream = tcpClient.GetStream()Dim readBytes() As [Byte] = New Byte(255) {}DonetStream.Read ( readBytes , 0, 0)Loop While netStream.DataAvailabletcpClient.Close()netStream.Close()
- Dim tcpClient As New TcpClient("www.conto so.com", 80)Dim netStream As NetworkStream = tcpClient.GetStream()Dim readBytes() As [Byte] = New Byte(255) {}DonetStream.Read ( readBytes , 0, readBytes.Length )Loop While netStream.DataAvailabletcpClient.Clos e()netStream.Close()
- Dim tcpCli ent As New TcpClient("www.conto so.com", 80)tcpClient.Connect("www.conto so.com", 80)
- netStream As NetworkStream = tcpClient.GetStream()Dim readBytes() As [Byte] = New Byte(255) {}DonetStream.Read ( readBytes , 0, 0)Loop While netStream.DataAvailabletcpClient.Close()netStream.Close()D. Dim tcpClient As New TcpClient()tcpClient.Connect("www.conto so.com", 80)Dim socket As New Socket(AddressFamily.InterNetwork, _SocketType.Stream, ProtocolType.Tcp)Dim netStream As New NetworkStream(socket)Dim readBytes() As [Byte] = New Byte(255) {}DonetStream.Read ( readBytes , 0, readBytes.Length )Loop While netStream.DataAvailabletcpClient.Close()netStream.Close()
Correct Answer
Dim tcpClient As New TcpClient("www.conto so.com", 80)Dim netStream As NetworkStream = tcpClient.GetStream()Dim readBytes() As [Byte] = New Byte(255) {}DonetStream.Read ( readBytes , 0, readBytes.Length )Loop While netStream.DataAvailabletcpClient.Clos e()netStream.Close()