2019-05-02 22:41:45 +03:00
|
|
|
|
using System;
|
2019-05-03 17:08:48 +03:00
|
|
|
|
using System.Collections.Generic;
|
2019-05-02 22:41:45 +03:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2019-05-03 17:08:48 +03:00
|
|
|
|
using Steamworks.Data;
|
2019-05-02 22:41:45 +03:00
|
|
|
|
|
|
|
|
|
namespace Steamworks
|
|
|
|
|
{
|
2020-02-22 14:17:12 +03:00
|
|
|
|
[TestClass]
|
2019-05-02 22:41:45 +03:00
|
|
|
|
[DeploymentItem( "steam_api64.dll" )]
|
2020-02-19 18:29:18 +03:00
|
|
|
|
[DeploymentItem( "steam_api.dll" )]
|
2020-02-22 14:17:12 +03:00
|
|
|
|
public partial class NetworkingSocketsTest
|
2019-05-02 22:41:45 +03:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task CreateRelayServer()
|
|
|
|
|
{
|
2019-05-03 17:08:48 +03:00
|
|
|
|
var si = SteamNetworkingSockets.CreateRelaySocket<TestSocketInterface>();
|
2019-05-02 22:41:45 +03:00
|
|
|
|
|
2019-05-03 17:08:48 +03:00
|
|
|
|
Console.WriteLine( $"Created Socket: {si}" );
|
2019-05-02 22:41:45 +03:00
|
|
|
|
|
|
|
|
|
// Give it a second for something to happen
|
2019-05-03 17:08:48 +03:00
|
|
|
|
await Task.Delay( 1000 );
|
2019-05-02 22:41:45 +03:00
|
|
|
|
|
2019-05-03 17:08:48 +03:00
|
|
|
|
si.Close();
|
2019-05-02 22:41:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task CreateNormalServer()
|
|
|
|
|
{
|
2019-05-06 15:34:41 +03:00
|
|
|
|
var si = SteamNetworkingSockets.CreateNormalSocket<TestSocketInterface>( Data.NetAddress.AnyIp( 21893 ) );
|
2019-05-02 22:41:45 +03:00
|
|
|
|
|
2019-05-03 17:08:48 +03:00
|
|
|
|
Console.WriteLine( $"Created Socket: {si}" );
|
2019-05-02 22:41:45 +03:00
|
|
|
|
|
|
|
|
|
// Give it a second for something to happen
|
2019-05-03 17:08:48 +03:00
|
|
|
|
await Task.Delay( 1000 );
|
2019-05-02 22:41:45 +03:00
|
|
|
|
|
2019-05-03 17:08:48 +03:00
|
|
|
|
si.Close();
|
2019-05-02 22:41:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-05-03 17:08:48 +03:00
|
|
|
|
public async Task RelayEndtoEnd()
|
2019-05-02 22:41:45 +03:00
|
|
|
|
{
|
2020-02-19 18:29:18 +03:00
|
|
|
|
SteamNetworkingUtils.InitRelayNetworkAccess();
|
|
|
|
|
|
2020-02-22 14:17:12 +03:00
|
|
|
|
// For some reason giving steam a couple of seconds here
|
|
|
|
|
// seems to prevent it returning null connections from ConnectNormal
|
|
|
|
|
await Task.Delay( 2000 );
|
|
|
|
|
|
2020-02-19 18:29:18 +03:00
|
|
|
|
Console.WriteLine( $"----- Creating Socket Relay Socket.." );
|
2020-02-22 14:17:12 +03:00
|
|
|
|
var socket = SteamNetworkingSockets.CreateRelaySocket<TestSocketInterface>( 6 );
|
2019-05-03 17:08:48 +03:00
|
|
|
|
var server = socket.RunAsync();
|
2019-05-02 22:41:45 +03:00
|
|
|
|
|
2020-02-22 14:17:12 +03:00
|
|
|
|
await Task.Delay( 1000 );
|
2020-02-19 18:29:18 +03:00
|
|
|
|
|
|
|
|
|
Console.WriteLine( $"----- Connecting To Socket via SteamId ({SteamClient.SteamId})" );
|
2020-02-22 14:17:12 +03:00
|
|
|
|
var connection = SteamNetworkingSockets.ConnectRelay<TestConnectionInterface>( SteamClient.SteamId, 6 );
|
2019-05-03 17:08:48 +03:00
|
|
|
|
var client = connection.RunAsync();
|
2019-05-02 22:41:45 +03:00
|
|
|
|
|
2019-05-03 17:08:48 +03:00
|
|
|
|
await Task.WhenAll( server, client );
|
|
|
|
|
}
|
2019-05-02 22:41:45 +03:00
|
|
|
|
|
2019-05-07 19:42:03 +03:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task NormalEndtoEnd()
|
|
|
|
|
{
|
2020-02-22 14:17:12 +03:00
|
|
|
|
// For some reason giving steam a couple of seconds here
|
|
|
|
|
// seems to prevent it returning null connections from ConnectNormal
|
|
|
|
|
await Task.Delay( 2000 );
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Start the server
|
|
|
|
|
//
|
|
|
|
|
Console.WriteLine( "CreateNormalSocket" );
|
2019-05-07 19:42:03 +03:00
|
|
|
|
var socket = SteamNetworkingSockets.CreateNormalSocket<TestSocketInterface>( NetAddress.AnyIp( 12445 ) );
|
|
|
|
|
var server = socket.RunAsync();
|
|
|
|
|
|
2020-02-22 14:17:12 +03:00
|
|
|
|
//
|
|
|
|
|
// Start the client
|
|
|
|
|
//
|
|
|
|
|
Console.WriteLine( "ConnectNormal" );
|
2019-05-07 19:42:03 +03:00
|
|
|
|
var connection = SteamNetworkingSockets.ConnectNormal<TestConnectionInterface>( NetAddress.From( System.Net.IPAddress.Parse( "127.0.0.1" ), 12445 ) );
|
|
|
|
|
var client = connection.RunAsync();
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll( server, client );
|
|
|
|
|
}
|
2019-05-02 22:41:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 18:29:18 +03:00
|
|
|
|
}
|