Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


XNA and VB.NET + C#


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 programmer100   Members   -  Reputation: 109

Like
0Likes
Like

Posted 12 September 2013 - 02:46 AM

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:

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()
        RequestLoop()
        [Exit]()
        Dim attempts As Integer = 0
 
        While Not _clientSocket.Connected
            Try
                attempts += 1
                Console.WriteLine("Connection attempt " & attempts)
                _clientSocket.Connect(IPAddress.Loopback, _PORT)
            Catch generatedExceptionName As SocketException
                Console.Clear()
            End Try
        End While
 
        Console.Clear()
        Console.WriteLine("Connected")
    End Sub
    Private Shared Sub RequestLoop()
        Console.WriteLine("<Type ""exit"" to properly disconnect client>")
 
        While True
            SendRequest("")
            ReceiveResponse()
        End While
    End Sub
    ''' <summary>
    ''' Close socket and exit app
    ''' </summary>
    Private Shared Sub [Exit]()
        SendString("exit")
        ' Tell the server we re exiting
        _clientSocket.Shutdown(SocketShutdown.Both)
        _clientSocket.Close()
        Environment.[Exit](0)
    End Sub
    Private Shared Sub SendRequest(text As String)
        Console.Write("Send a request: ")
        Dim request As String = text
        SendString(request)
 
        If request.ToLower() = "exit" Then
            [Exit]()
        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
            Return
        End If
        Dim data = New Byte(received - 1) {}
        Array.Copy(buffer, data, received)
        Dim text As String = Encoding.ASCII.GetString(data)
        Console.WriteLine(text)
 
        If text.ToLower() = "movedup" Then
            MsgBox("test")
        End If
    End Sub
End Class



Error when i run program:

System.Net.Sockets.SocketException was unhandled
ErrorCode=10057
HResult=-2147467259
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
NativeErrorCode=10057
Source=System
StackTrace:
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
InnerException:



Sponsor:

#2 hplus0603   Moderators   -  Reputation: 5509

Like
1Likes
Like

Posted 13 September 2013 - 11:10 AM

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


enum Bool { True, False, FileNotFound };

#3 programmer100   Members   -  Reputation: 109

Like
0Likes
Like

Posted 16 September 2013 - 08:45 AM

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.



#4 hplus0603   Moderators   -  Reputation: 5509

Like
0Likes
Like

Posted 16 September 2013 - 09:44 AM

One error more and i have no idea what do.


Then you are stuck and cannot make progress.
enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS