Jump to content
  • Advertisement
Sign in to follow this  

XNA and VB.NET + C#

This topic is 2130 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I have small problem! I try make XNA multiplayer game using VB.NET, but my client socket not working on XNA but working VB.NET and C#. Server get sended data but game get error when try receive data and two small error.

XNA code:
[PHP]Public Class Server

    Private Shared _clientSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
    Private Shared _PORT As Integer = 21
    Public Shared Sub ConnectToServer()
        Dim attempts As Integer = 0
        While Not _clientSocket.Connected
                attempts += 1
                Console.WriteLine("Connection attempt " & attempts)
                _clientSocket.Connect(IPAddress.Loopback, _PORT)
            Catch generatedExceptionName As SocketException
            End Try
        End While
    End Sub
    Private Shared Sub RequestLoop()
        Console.WriteLine("<Type ""exit"" to properly disconnect client>")
        While True
        End While
    End Sub
    ''' <summary>
    ''' Close socket and exit app
    ''' </summary>
    Private Shared Sub [Exit]()
        ' Tell the server we re exiting
    End Sub
    Private Shared Sub SendRequest(text As String)
        Console.Write("Send a request: ")
        Dim request As String = text
        If request.ToLower() = "exit" Then
        End If
    End Sub
    ''' <summary>
    ''' Sends a string to the server with ASCII encoding
    ''' </summary>
    Public Shared Sub SendString(text As String)
        If text <> "" Then
            Dim buffer As Byte() = Encoding.ASCII.GetBytes(text)
            _clientSocket.Send(buffer, 0, buffer.Length, SocketFlags.None)
        End If
    End Sub
    Private Shared Sub ReceiveResponse()
        Dim buffer = New Byte(2047) {}
        Dim received As Integer = _clientSocket.Receive(buffer, SocketFlags.None)
        If received = 0 Then
        End If
        Dim data = New Byte(received - 1) {}
        Array.Copy(buffer, data, received)
        Dim text As String = Encoding.ASCII.GetString(data)
        If text.ToLower() = "movedup" Then
        End If
    End Sub
End Class


Error when i run program:

[PHP]System.Net.Sockets.SocketException was unhandled
Message=Tietojen lähetys- tai vastaanottopyyntö hylättiin, koska vastake ei ole kytketty ja (lähetettäessä datagrammivastakkeeseen Sendto-kutsua käyttäen) osoitetta ei määritetty
kohteessa System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
kohteessa System.Net.Sockets.Socket.Receive(Byte[] buffer, SocketFlags socketFlags)
kohteessa XNAgame.Server.ReceiveResponse() Server.vb:rivillä 66
kohteessa XNAgame.Server.RequestLoop() Server.vb:rivillä 31
kohteessa XNAgame.Server.ConnectToServer() Server.vb:rivillä 8
kohteessa XNAgame.Game1..ctor() tiedostossa Game1.vb:rivillä 6
kohteessa XNAgame.Program.Main(String[] args) Program.vb:rivillä 8

Share this post

Link to post
Share on other sites

The stack trace tells you what the problem is. It tells you that you're calling SendString() on a string that is null.


I fixed it. One error more and i have no idea what do.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!