diff --git a/Facepunch.Steamworks.Test/NetworkingSockets.cs b/Facepunch.Steamworks.Test/NetworkingSockets.cs index 9bf8e66..80aafbf 100644 --- a/Facepunch.Steamworks.Test/NetworkingSockets.cs +++ b/Facepunch.Steamworks.Test/NetworkingSockets.cs @@ -99,6 +99,7 @@ namespace Steamworks while ( Connected ) { + Receive(); await Task.Delay( 10 ); } } diff --git a/Facepunch.Steamworks/Classes/ConnectionInterface.cs b/Facepunch.Steamworks/Classes/ConnectionInterface.cs index f58a96e..c6cdb73 100644 --- a/Facepunch.Steamworks/Classes/ConnectionInterface.cs +++ b/Facepunch.Steamworks/Classes/ConnectionInterface.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.IO; using Steamworks.Data; namespace Steamworks @@ -64,5 +66,38 @@ namespace Steamworks { Connected = false; } + + SteamNetworkingMessage_t[] messageBuffer; + + public void Receive() + { + if ( messageBuffer == null ) + { + messageBuffer = new SteamNetworkingMessage_t[128]; + } + + var processed = SteamNetworkingSockets.Internal.ReceiveMessagesOnConnection( Connection, ref messageBuffer, messageBuffer.Length ); + + for ( int i=0; i< processed; i++ ) + { + Console.WriteLine( "FOUND SOME!" ); + ReceiveMessage( messageBuffer[i] ); + } + + // + // Overwhelmed our buffer, keep going + // + if ( processed == messageBuffer.Length ) + Receive(); + } + + internal unsafe void ReceiveMessage( SteamNetworkingMessage_t msg ) + { + var stream = new UnmanagedMemoryStream( (byte*)msg.data, msg.length, msg.length, FileAccess.Read ); + + // read Message + + msg.release.Invoke( ref msg ); + } } } \ No newline at end of file