Dim
strHost As StringstrHost = System.Net.Dns.GetHostName()
MessageBox.Show(strHost, "実行結果")
Dim
strHost As String Dim ip As System.Net.IPHostEntry Dim ipAddr As System.Net.IPAddress 'ホスト名を取得strHost = System.Net.Dns.GetHostName()
'IPリストを取得ip = System.Net.Dns.GetHostByName(strHost)
'IPリストの最初を取得ipAddr = ip.AddressList(0)
'ピリオド付きで表示するMessageBox.Show(ipAddr.ToString(), "実行結果")
'TCP接続を行う
Dim tcpClient As New System.Net.Sockets.TcpClient() TrytcpClient.Connect("www.microsoft.com", 80)
MessageBox.Show("接続できた", "実行結果")
tcpClient.Close()
Catch ex As Exception '接続が出来なかった場合は例外が発生するMessageBox.Show(ex.ToString(), "実行結果")
End Try'サーバーに接続する
Dim tcpClient As New System.Net.Sockets.TcpClient()tcpClient.Connect("www.microsoft.com", 80)
'ストリームを取得する Dim Stream As System.Net.Sockets.NetworkStreamStream = tcpClient.GetStream
'送信データを作成する Dim bytSend As Byte()bytSend = System.Text.Encoding.ASCII.GetBytes( _
"GET /Default.asp HTTP/1.0" + vbCrLf + vbCrLf)
'送信準備が出来ていれば送信する If Stream.CanWrite() = True Then TryStream.Write(bytSend, 0, bytSend.Length)
MessageBox.Show("データ送信しました", "実行結果")
Catch ex As ExceptionMessageBox.Show(ex.ToString(), "実行結果")
End Try ElseMessageBox.Show("送信に失敗しました", "実行結果")
End IftcpClient.Close()
'サーバーに接続する
Dim tcpClient As New System.Net.Sockets.TcpClient()tcpClient.Connect("www.microsoft.com", 80)
'ストリームを作成しデータ送信する Dim Stream As System.Net.Sockets.NetworkStream = tcpClient.GetStream() Dim bytSend As Byte() = System.Text.Encoding.ASCII.GetBytes("GET /Default.asp HTTP/1.0" + ControlChars.CrLf + ControlChars.CrLf)Stream.Write(bytSend, 0, bytSend.Length())
'受信バッファを用意する Dim bytRead(2000) As Byte Dim strText As String Dim intLength As Integer 'ストリームからデータを受信するstrText = ""
DointLength = Stream.Read(bytRead, 0, bytRead.Length())
strText += System.Text.Encoding.ASCII.GetString(bytRead, 0, intLength)
If intLength < bytRead.Length Then Exit Do End IftcpClient.Close()
LoopTextBox1.Text = strText
HTTPサーバーに接続する
Dim
webClient As New System.Net.WebClient() Dim sr As System.IO.Stream =webClient.OpenRead("http://www.microsoft.com/") Dim srRead As New System.IO.StreamReader(sr)TextBox1.Text = srRead.ReadToEnd()
srRead.Close()