Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,976 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,389 people online right now. Registration is fast and FREE... Join Now!




Making Udp connection

 
Reply to this topicStart new topic

Making Udp connection

Syperus
17 Dec, 2007 - 02:17 PM
Post #1

New D.I.C Head
*

Joined: 15 Dec, 2007
Posts: 5


My Contributions
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.

CODE

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

CODE

Hostname: disconnect


Any help on this would be greatly appreciated. Thanks


User is offlineProfile CardPM
+Quote Post

computermat
RE: Making Udp Connection
14 Apr, 2008 - 09:31 AM
Post #2

New D.I.C Head
*

Joined: 14 Apr, 2008
Posts: 2

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
User is offlineProfile CardPM
+Quote Post

G0ggy
RE: Making Udp Connection
21 Apr, 2008 - 04:18 AM
Post #3

New D.I.C Head
*

Joined: 14 Jun, 2007
Posts: 1


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

CODE
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

User is offlineProfile CardPM
+Quote Post

computermat
RE: Making Udp Connection
21 Apr, 2008 - 08:38 AM
Post #4

New D.I.C Head
*

Joined: 14 Apr, 2008
Posts: 2

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"

CODE

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 Apr, 2008 - 08:44 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 06:51PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month