Arminizer_88
چهارشنبه 10 خرداد 1385, 12:32 عصر
من یه مشکل دارم که نمیدونم علتش چیه. برنامه از این قراره که یک IP رو میگیریم و اگر وضعیتش Success بود سعی میکنیم با یک TcpClient بهش وصل شیم. کد برنامه از این قراره:
Dim IPHostEntry As IPHostEntry = Dns.GetHostEntry("")
Dim Ping As New Ping
Dim Result As PingReply
Try
Result = Ping.Send(IPHostEntry.AddressList(0).ToString)
If Result.Status.ToString = "Success" Then
'Connect to ipaddress
Dim client As New TcpClient
client.Connect(IPHostEntry.AddressList(0).ToString , 11009)
MsgBox("Connected to '" & IPHostEntry.AddressList(0).ToString & "'", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "TcpClient")
client.Close()
End If
'Exit Application
Global.System.Windows.Forms.Application.Exit()
Catch ex As SocketException
MsgBox(ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkCancel, "SocketException")
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkCancel, "ErrorException")
End Try
Dim IPHostEntry As IPHostEntry = Dns.GetHostEntry("")
Dim Ping As New Ping
Dim Result As PingReply
Try
Result = Ping.Send(IPHostEntry.AddressList(0).ToString)
If Result.Status.ToString = "Success" Then
'Connect to ipaddress
Dim client As New TcpClient
client.Connect(IPHostEntry.AddressList(0).ToString , 11009)
MsgBox("Connected to '" & IPHostEntry.AddressList(0).ToString & "'", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "TcpClient")
client.Close()
End If
'Exit Application
Global.System.Windows.Forms.Application.Exit()
Catch ex As SocketException
MsgBox(ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkCancel, "SocketException")
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkCancel, "ErrorException")
End Try