5 Replies - 2234 Views - Last Post: 21 April 2009 - 05:29 AM Rate Topic: -----

#1 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 161
  • Joined: 09-August 08

udp client not responding

Posted 08 April 2009 - 06:55 AM

hi all i have nearly finished my game matchmaker now and im stuck on one final thing... this is how the app works...

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


Is This A Good Question/Topic? 0
  • +

Replies To: udp client not responding

#2 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: udp client not responding

Posted 08 April 2009 - 06:48 PM

You dont call Socket.Connect on a socket using UDP.

Checkout the Socket Class documentations for some a better understanding of how the class works

http://msdn.microsof...ets.socket.aspx

Here is how to send with a UDP socket.
http://msdn.microsof...y/eae4f5y0.aspx
Was This Post Helpful? 0
  • +
  • -

#3 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 161
  • Joined: 09-August 08

Re: udp client not responding

Posted 09 April 2009 - 06:33 AM

thanks i will look at that
Was This Post Helpful? 0
  • +
  • -

#4 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 161
  • Joined: 09-August 08

Re: udp client not responding

Posted 13 April 2009 - 02:41 PM

i have looked in to this and i cant seam to make a connection to my server,

my server forces the connection closed and i just get a error to say that, i dont know where to go from here, i even copyed the code from the 1st link changing the credentials to my details and went thought the 2nd link but still couldnt get a connection :S

thanks again for the replay tho

is there anythingelse i can do to have the effect i need?? my code above ONLY errors if there is a dead ip with no server running and there is always going to be a few of them

i have tryed this...

If UdpClient.Client.Connected = False Then


				Lists = ("					  SERVER CLOSED			   ")
				

						  Else
				Lists =( show the server info)



			End If



but still dont seam to work it just seams to find the dead link and not show any open servers on screen


TADS

This post has been edited by TADS: 13 April 2009 - 02:44 PM

Was This Post Helpful? 0
  • +
  • -

#5 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 161
  • Joined: 09-August 08

Re: udp client not responding

Posted 13 April 2009 - 05:18 PM

at last i have sorted it!!!!! in the 1st post in the 2nd lot of code

 Dim receiveBytes As [Byte]() = UdpClient.Receive(RemoteIpEndPoint)



just replace it with....


Dim receiveBytes As [Byte]() = UdpClient.Receive(RemoteIpEndPoint)
			If receiveBytes.Length = False Then

				UdpClient.Client.EndReceive(RemoteIpEndPoint)

			End If



and it stops the socket and moves on to the next ip in the list :)

TADS
Was This Post Helpful? 1
  • +
  • -

#6 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: udp client not responding

Posted 21 April 2009 - 05:29 AM

Gratz!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1