mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-27 22:18:11 +03:00
Message send/recv tests
This commit is contained in:
parent
f77332a41f
commit
cdeccc5afe
@ -30,6 +30,7 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
@ -39,6 +40,7 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@ -48,6 +50,7 @@
|
|||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||||
<OutputPath>bin\x64\Release\</OutputPath>
|
<OutputPath>bin\x64\Release\</OutputPath>
|
||||||
@ -57,6 +60,7 @@
|
|||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@ -66,6 +70,7 @@
|
|||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||||
<OutputPath>bin\x86\Release\</OutputPath>
|
<OutputPath>bin\x86\Release\</OutputPath>
|
||||||
@ -75,6 +80,7 @@
|
|||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
@ -96,10 +96,19 @@ namespace Steamworks
|
|||||||
|
|
||||||
Console.WriteLine( "[Connection] Hey We're Connected!" );
|
Console.WriteLine( "[Connection] Hey We're Connected!" );
|
||||||
|
|
||||||
|
var sw = System.Diagnostics.Stopwatch.StartNew();
|
||||||
|
|
||||||
|
|
||||||
while ( Connected )
|
while ( Connected )
|
||||||
{
|
{
|
||||||
Receive();
|
Receive();
|
||||||
await Task.Delay( 10 );
|
await Task.Delay( 100 );
|
||||||
|
|
||||||
|
if ( sw.Elapsed.TotalSeconds > 5 )
|
||||||
|
{
|
||||||
|
Console.WriteLine( "CLIENT ERROR!!!!! TIMED OUT" );
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,9 +119,26 @@ namespace Steamworks
|
|||||||
|
|
||||||
Console.WriteLine( $"[Connection][{messageNum}][{recvTime}][{channel}] \"{str}\"" );
|
Console.WriteLine( $"[Connection][{messageNum}][{recvTime}][{channel}] \"{str}\"" );
|
||||||
|
|
||||||
if ( str.StartsWith( "Hello" ) )
|
if ( str.Contains( "Hello" ) )
|
||||||
{
|
{
|
||||||
Connection.SendMessage( "Hello, How are you!?" );
|
Connection.SendMessage( "Hello, How are you!?" );
|
||||||
|
|
||||||
|
Connection.SendMessage( "How do you like 20 messages in a row?" );
|
||||||
|
|
||||||
|
for ( int i=0; i<20; i++ )
|
||||||
|
{
|
||||||
|
Connection.SendMessage( $"BLAMMO!" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( str.Contains( "how about yourself" ) )
|
||||||
|
{
|
||||||
|
Connection.SendMessage( "I'm great, but I have to go now, bye." );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( str.Contains( "hater" ) )
|
||||||
|
{
|
||||||
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -173,14 +199,43 @@ namespace Steamworks
|
|||||||
await Task.Delay( 300 );
|
await Task.Delay( 300 );
|
||||||
singleClient.SendMessage( "Hello Client!?" );
|
singleClient.SendMessage( "Hello Client!?" );
|
||||||
|
|
||||||
await Task.Delay( 1000 );
|
var sw = System.Diagnostics.Stopwatch.StartNew();
|
||||||
|
|
||||||
singleClient.Close();
|
while ( Connected.Contains( singleClient ) )
|
||||||
|
{
|
||||||
|
Receive();
|
||||||
|
await Task.Delay( 100 );
|
||||||
|
|
||||||
|
if ( sw.Elapsed.TotalSeconds > 5 )
|
||||||
|
{
|
||||||
|
Assert.Fail( "Took too long" );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await Task.Delay( 1000 );
|
await Task.Delay( 1000 );
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override unsafe void OnMessage( NetConnection connection, NetworkIdentity identity, IntPtr data, int size, long messageNum, SteamNetworkingMicroseconds recvTime, int channel )
|
||||||
|
{
|
||||||
|
// We're only sending strings, so it's fine to read this like this
|
||||||
|
var str = UTF8Encoding.UTF8.GetString( (byte*)data, size );
|
||||||
|
|
||||||
|
Console.WriteLine( $"[SOCKET][{connection}[{identity}][{messageNum}][{recvTime}][{channel}] \"{str}\"" );
|
||||||
|
|
||||||
|
if ( str.Contains( "Hello, How are you" ) )
|
||||||
|
{
|
||||||
|
connection.SendMessage( "I'm great thanks, how about yourself?" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( str.Contains( "bye" ) )
|
||||||
|
{
|
||||||
|
connection.SendMessage( "See you later, hater." );
|
||||||
|
connection.Close( true, 10, "Said Bye" );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ namespace Steamworks
|
|||||||
break;
|
break;
|
||||||
case ConnectionState.ClosedByPeer:
|
case ConnectionState.ClosedByPeer:
|
||||||
case ConnectionState.ProblemDetectedLocally:
|
case ConnectionState.ProblemDetectedLocally:
|
||||||
|
case ConnectionState.None:
|
||||||
OnDisconnected( data );
|
OnDisconnected( data );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -78,7 +79,8 @@ namespace Steamworks
|
|||||||
|
|
||||||
for ( int i = 0; i < processed; i++ )
|
for ( int i = 0; i < processed; i++ )
|
||||||
{
|
{
|
||||||
ReceiveMessage( Marshal.ReadIntPtr( messageBuffer, i ) );
|
// #32bit
|
||||||
|
ReceiveMessage( Marshal.ReadIntPtr( messageBuffer, i * 8) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using Steamworks.Data;
|
using Steamworks.Data;
|
||||||
|
|
||||||
namespace Steamworks
|
namespace Steamworks
|
||||||
@ -25,6 +27,7 @@ namespace Steamworks
|
|||||||
break;
|
break;
|
||||||
case ConnectionState.ClosedByPeer:
|
case ConnectionState.ClosedByPeer:
|
||||||
case ConnectionState.ProblemDetectedLocally:
|
case ConnectionState.ProblemDetectedLocally:
|
||||||
|
case ConnectionState.None:
|
||||||
OnDisconnected( connection, data );
|
OnDisconnected( connection, data );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -58,5 +61,54 @@ namespace Steamworks
|
|||||||
Connecting.Remove( connection );
|
Connecting.Remove( connection );
|
||||||
Connected.Remove( connection );
|
Connected.Remove( connection );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Receive( int bufferSize = 32 )
|
||||||
|
{
|
||||||
|
// #32bit
|
||||||
|
int processed = 0;
|
||||||
|
IntPtr messageBuffer = Marshal.AllocHGlobal( 8 * bufferSize );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
processed = SteamNetworkingSockets.Internal.ReceiveMessagesOnListenSocket( Socket, messageBuffer, bufferSize );
|
||||||
|
|
||||||
|
for ( int i = 0; i < processed; i++ )
|
||||||
|
{
|
||||||
|
// #32bit
|
||||||
|
ReceiveMessage( Marshal.ReadIntPtr( messageBuffer, i * 8 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Marshal.FreeHGlobal( messageBuffer );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Overwhelmed our buffer, keep going
|
||||||
|
//
|
||||||
|
if ( processed == bufferSize )
|
||||||
|
Receive( bufferSize );
|
||||||
|
}
|
||||||
|
|
||||||
|
internal unsafe void ReceiveMessage( IntPtr msgPtr )
|
||||||
|
{
|
||||||
|
var msg = Marshal.PtrToStructure<NetMsg>( msgPtr );
|
||||||
|
try
|
||||||
|
{
|
||||||
|
OnMessage( msg.Connection, msg.Identity, msg.DataPtr, msg.DataSize, msg.TimeRecv, msg.MessageNumber, msg.Channel );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Releases the message
|
||||||
|
//
|
||||||
|
msg.Release( msgPtr );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnMessage( NetConnection connection, NetworkIdentity identity, IntPtr data, int size, long messageNum, SteamNetworkingMicroseconds recvTime, int channel )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user