4 Replies - 18949 Views - Last Post: 07 November 2010 - 05:38 PM Rate Topic: -----

#1 Syperus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-December 07

Making Udp connection

Posted 17 December 2007 - 03:17 PM

Hello, im making a gaming tool for my Call of Duty 4 server. Not sure if anyone here plays it, but it uses an ingame rcon command tool that you use for admin control on your server. Well i wanted to make a program that i can control my server without having to log ingame to do admin stuff. I seem to be having problems tho. Im trying to have my program retrieve current information on the server but can't seem to retrieve the information. I have been reading serveral UDP tutorials trying to learn udp and tcp. Im definately still new to all this and trying my hardest to learn. Here is my code. I commented parts to explain what its for incase noone knows what it is for the game.

Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.IO


Public Class Form1
	Inherits System.Windows.Forms.Form

' rconPassword is the password to login for admin control
	Dim sPass As String = "/rcon login rconPassword"
' sv_hostname is the variable on the server that has text im trying to receive	
Dim hostName As String = "sv_hostname"

' multi-line textbox named txtBox1 for sending the information to, to read
Private Sub txt(ByVal Text As String)
		txtBox1.AppendText(Text & vbCrLf)
		txtBox1.ScrollToCaret()
	End Sub

	Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
		
		Dim udpClient As New UdpClient(12345)
		Try
			' Not the real ip address or port number
			udpClient.Connect("123.45.67.89", 12345)

			' Here i try to send the login attempt and hostname request
			Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(sPass & hostName)


			udpClient.Send(sendBytes, sendBytes.Length)

			
			Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)

			
			Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)
			Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)

		   
			txt("Hostname: " + returnData.ToString())
			
			udpClient.Close()


		Catch ex As Exception
			txt(ex.ToString())
		End Try
	End Sub
End Class



And the response i get from this is

Hostname: disconnect



Any help on this would be greatly appreciated. Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Making Udp connection

#2 computermat  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 14-April 08

Re: Making Udp connection

Posted 14 April 2008 - 10:31 AM

I have been wanting to do something similar, did you ever manage to get it working, if so could you share your connection code?

Thanks
Matt
Was This Post Helpful? 0
  • +
  • -

#3 G0ggy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-June 07

Re: Making Udp connection

Posted 21 April 2008 - 05:18 AM

Just to bump this thread, I get (almost) the same response:

Imports System.Net.Sockets
Imports System.Text
Imports System.Net

Public Class Form1

	Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim udpClient As New UdpClient(11000)

		Try
			udpClient.Connect("193.47.83.222", "28934")

			Dim sendBytes As [Byte]() = Encoding.UTF8.GetBytes("/rcon login rconpassword")

			udpClient.Send(sendBytes, sendBytes.Length)

			Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)

			Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)
			Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)

			' Which one of these two hosts responded?
			TextBox1.Text = (("This is the message you received " + _
										  returnData.ToString()))
			TextBox1.Text = TextBox1.Text & vbCrLf & (("This message was sent from " + _
										 RemoteIpEndPoint.Address.ToString() + _
										 " on their port number " + _
										 RemoteIpEndPoint.Port.ToString()))
			udpClient.Close()
		Catch ex As Exception
			Console.WriteLine(e.ToString())
		End Try
	End Sub
End Class


Quote

This is the message you received ????disconnect
This message was sent from 193.47.83.222 on their port number 28934

Was This Post Helpful? 0
  • +
  • -

#4 computermat  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 14-April 08

Re: Making Udp connection

Posted 21 April 2008 - 09:38 AM

Well I have posted on other sites and im still no closer, I have just made a post on IW forums see if one of their devs picks it up and can help us out, seems like there are quite a few people with this problem.

Yes I get "Disconnected"

Public Class Form1
	Private Sub btnCONNECT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCONNECT.Click
		Dim client As New System.Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Dgram, Net.Sockets.ProtocolType.Udp)
		Dim command As String = "˙˙˙˙rcon" & txtPASS.Text & " say Is this working?"
		Dim sendBuffer() As Byte = System.Text.Encoding.UTF8.GetBytes(command)
		Dim receivedReply As Boolean
		Dim availableBytes As Integer

		client.Connect(txtIP.Text, txtPORT.Text)
		client.Send(sendBuffer, sendBuffer.Length, Net.Sockets.SocketFlags.None)

		Do
			availableBytes = client.Available
			If (availableBytes > 0) Then
				Dim receiveBuffer(availableBytes - 1) As Byte
				client.Receive(receiveBuffer, availableBytes, Net.Sockets.SocketFlags.None)
				MessageBox.Show(System.Text.Encoding.UTF8.GetString(receiveBuffer))
				receivedReply = True
			End If
		Loop Until receivedReply
	End Sub
End Class


This post has been edited by computermat: 21 April 2008 - 09:44 AM

Was This Post Helpful? 1
  • +
  • -

#5 SLeePYG72786  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-September 10

Re: Making Udp connection

Posted 07 November 2010 - 05:38 PM

I understand this is a dead thread, but I'm trying to doing the exact same thing. The code at the end of the first post

UdpClient.Close()

is what I thought was making it show Hostname: ????disconnect. So I tried removing that line, and it showed it.

We are currently using a VB6 version of a program to control our servers, but we REALLY want to update our program to vb.net framework 4.0.

If anyone has ANY information on this, PLEASE post it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1