form load -> read line by line from a text file -> query each line(witch is an ip) -> display the data in a line in a listbox... this loops round for each line(ip) in the text file and make a new line in listbox each time... all works just right im very happy... now for the problem im having...
while this loop is running if the query finds an ip that is not online (game server is not up) it just stops and dose nothing atall BUT if i make a seperate query for say 2-3 ips with the ip hard coded so it takes the loop out if an ip is not online it tells me server is offline so is there anyway i could make this do a timeout or something... like if the server dont respond withing 5 seconds it closes the connection to that query and moves on?? my code is below for all of the above..
FORM LOAD
ListBox1.Items.Add("Users" + " | " + "Race Lenength " + " | " + "Track" + " | " + "Realisum" + " | " + "Server IP" + " | " + "Server Name")
ListBox1.Items.Add("........................................................................................................................................................")
Me.read()
THE QUERY SUB
Public Sub ipquery()
Try
UdpClient.Connect(line, 2007)
UdpClient.Send(sendBytes, sendBytes.Length)
udpClientB.Send(sendBytes, sendBytes.Length, line, 2007)
Dim receiveBytes As [Byte]() = UdpClient.Receive(RemoteIpEndPoint)
Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
musers = returnData.Substring(16, 4)
musers = byte4toint(musers)
users = returnData.Substring(208, 4)
users = byte4toint(users)
sname = returnData.ToCharArray(20, 12)
Track = returnData.ToCharArray(71, 14)
real = returnData.ToCharArray(86, 10)
raceLen = returnData.ToCharArray(111, 8)
ListBox1.Items.Add("")
ListBox1.Items.Add(users + " \ " + musers + " | " + raceLen + " | " + Track + " | " + real + " | " + line + " | " + sname)
ListBox1.Items.Add("_____________________________________________________________________________")
ListBox1.Name = line
Catch
MsgBox("server not open")
End Try
End Sub
HOW I READ LINE BY LINE
Sub read() Try Do While Not (line Is Nothing) ' Trim and make sure the line isn't blank. line = line.Trim() If line.Length > 0 Then Me.ipquery() line = stream_reader.ReadLine() Loop 'ListBox2.SelectedIndex = 0 stream_reader.Close() Catch exc As Exception ' Report all errors. MsgBox(exc.Message, MsgBoxStyle.Exclamation, "Read Error") End Try End Sub
Private Function tempdata() As String Dim file_name As String = Application.StartupPath + "\ip.txt" Return file_name End Function
if anyone can suggest a way to go would be Brill
Thanks for reading
TADS
This post has been edited by TADS: 08 April 2009 - 07:00 AM

New Topic/Question
Reply




MultiQuote




|