View Single Post
 
Old 04-05-2013, 03:03 AM
TrueBriT TrueBriT is offline
Newcomer
 
Join Date: Mar 2007
Posts: 5
Default Sockets index out if range

Hi guys im trying to connect to a game server that i currently have running from home, ive been doing a little bit of research on this but i can't seem to find out where im goin wrong.

i keep getting system.IndexOutOfRangeException error
also i have had once socket exception error heres my code

Code:
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Net.Sockets
Imports System.Net

Public Class frmRcon

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        sendComm("status", "5.70.250.66", "", 28960)
    End Sub

   Private Function sendComm(ByVal rconComm As String, ByVal gameIP As String, ByVal gamePass As String, ByVal gamePort As Integer) As String
        On Error Resume Next

        Dim client As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
        client.Connect(IPAddress.Parse(gameIP), gamePort)

        Dim command As String

        command = rconComm

        Dim bufferTemp() As Byte = Encoding.ASCII.GetBytes(command)
        Dim buffersend(bufferTemp.Length + 4) As Byte

        buffersend(0) = Byte.Parse("255")
        buffersend(1) = Byte.Parse("255")
        buffersend(2) = Byte.Parse("255")
        buffersend(3) = Byte.Parse("255")

        Dim j As Integer = 4
        For i As Integer = 0 To bufferTemp.Length - 1
            buffersend(j) = bufferTemp(i)
            j += i
        Next i

        Dim remoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
        client.Send(buffersend, SocketFlags.None)

        Dim bufferRec(64999) As Byte
        client.Receive(bufferRec)
        Return Encoding.ASCII.GetString(bufferRec)

    End Function
End Class
Reply With Quote