You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-06 02:11:06 +09:00
Wrong appidentifier now sends immediate Disconnect
BarebonesClient/Server added
This commit is contained in:
@@ -21,6 +21,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DurableServer", "Samples\Du
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DurableClient", "Samples\DurableClient\DurableClient.csproj", "{0B4B02BB-0F43-4466-A369-0682281AF60E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarebonesServer", "Samples\BarebonesServer\BarebonesServer.csproj", "{438173C5-8E95-4AE1-AAAB-5C1009F05302}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarebonesClient", "Samples\BarebonesClient\BarebonesClient.csproj", "{BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -63,6 +67,14 @@ Global
|
||||
{0B4B02BB-0F43-4466-A369-0682281AF60E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0B4B02BB-0F43-4466-A369-0682281AF60E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0B4B02BB-0F43-4466-A369-0682281AF60E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{438173C5-8E95-4AE1-AAAB-5C1009F05302}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{438173C5-8E95-4AE1-AAAB-5C1009F05302}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{438173C5-8E95-4AE1-AAAB-5C1009F05302}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{438173C5-8E95-4AE1-AAAB-5C1009F05302}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -75,5 +87,7 @@ Global
|
||||
{321F68AE-7F97-415E-A3F9-7C477EFF95EE} = {DA6697E7-4DD4-45EF-90A7-2FC265855019}
|
||||
{034984CA-FB37-44AF-BBF9-EC58ED75F5F3} = {DA6697E7-4DD4-45EF-90A7-2FC265855019}
|
||||
{0B4B02BB-0F43-4466-A369-0682281AF60E} = {DA6697E7-4DD4-45EF-90A7-2FC265855019}
|
||||
{438173C5-8E95-4AE1-AAAB-5C1009F05302} = {DA6697E7-4DD4-45EF-90A7-2FC265855019}
|
||||
{BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F} = {DA6697E7-4DD4-45EF-90A7-2FC265855019}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -485,6 +485,10 @@ namespace Lidgren.Network
|
||||
{
|
||||
// wrong app ident
|
||||
LogWarning("Connect received with wrong appidentifier (need '" + m_configuration.AppIdentifier + "' found '" + appIdent + "') from " + senderEndpoint);
|
||||
|
||||
NetOutgoingMessage bye = CreateLibraryMessage(NetMessageLibraryType.Disconnect, "Wrong app identifier!");
|
||||
SendUnconnectedLibraryMessage(bye, NetMessageLibraryType.Disconnect, senderEndpoint);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
58
Samples/BarebonesClient/BarebonesClient.csproj
Normal file
58
Samples/BarebonesClient/BarebonesClient.csproj
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{BC0CBAEE-70FE-4B1E-A2FA-BCC731F1E48F}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>BarebonesClient</RootNamespace>
|
||||
<AssemblyName>BarebonesClient</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Lidgren.Network\Lidgren.Network.csproj">
|
||||
<Project>{FA245447-5F23-4AA1-BD5F-8D2DDF33CFBD}</Project>
|
||||
<Name>Lidgren.Network</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
69
Samples/BarebonesClient/Program.cs
Normal file
69
Samples/BarebonesClient/Program.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
using Lidgren.Network;
|
||||
|
||||
namespace BarebonesClient
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
NetPeerConfiguration config = new NetPeerConfiguration("barebones");
|
||||
config.SimulatedLoss = 0.1f;
|
||||
NetClient client = new NetClient(config);
|
||||
client.Start();
|
||||
|
||||
Thread.Sleep(2000);
|
||||
|
||||
client.Connect("localhost", 14242);
|
||||
|
||||
while (Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
|
||||
{
|
||||
NetIncomingMessage inc;
|
||||
while ((inc = client.ReadMessage()) != null)
|
||||
{
|
||||
switch (inc.MessageType)
|
||||
{
|
||||
case NetIncomingMessageType.StatusChanged:
|
||||
NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte();
|
||||
string reason = inc.ReadString();
|
||||
Console.WriteLine("New status: " + status + " (" + reason + ")");
|
||||
if (status == NetConnectionStatus.Connected)
|
||||
{
|
||||
//
|
||||
// We're connected - send stuff
|
||||
//
|
||||
NetOutgoingMessage om = client.CreateMessage();
|
||||
|
||||
// temporary code to verify issue with large messages
|
||||
StringBuilder bdr = new StringBuilder();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
bdr.Append("Hallonsmurf" + i.ToString());
|
||||
om.Write(bdr.ToString());
|
||||
|
||||
client.SendMessage(om, NetDeliveryMethod.ReliableOrdered);
|
||||
}
|
||||
break;
|
||||
case NetIncomingMessageType.DebugMessage:
|
||||
case NetIncomingMessageType.VerboseDebugMessage:
|
||||
case NetIncomingMessageType.WarningMessage:
|
||||
case NetIncomingMessageType.ErrorMessage:
|
||||
Console.WriteLine(inc.ReadString());
|
||||
break;
|
||||
case NetIncomingMessageType.UnconnectedData:
|
||||
Console.WriteLine("Received unconnected data from " + inc.SenderEndpoint + ", conn is " + inc.SenderConnection);
|
||||
break;
|
||||
case NetIncomingMessageType.Data:
|
||||
Console.WriteLine("Received " + inc.LengthBytes + " bytes of data from " + inc.SenderConnection + ", endpoint is " + inc.SenderEndpoint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
Console.WriteLine("Application exiting");
|
||||
while (true) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Samples/BarebonesClient/Properties/AssemblyInfo.cs
Normal file
36
Samples/BarebonesClient/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("BarebonesClient")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("BarebonesClient")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("30270c13-84c7-4b20-971f-44adbd45635b")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
58
Samples/BarebonesServer/BarebonesServer.csproj
Normal file
58
Samples/BarebonesServer/BarebonesServer.csproj
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{438173C5-8E95-4AE1-AAAB-5C1009F05302}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>BarebonesServer</RootNamespace>
|
||||
<AssemblyName>BarebonesServer</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Lidgren.Network\Lidgren.Network.csproj">
|
||||
<Project>{FA245447-5F23-4AA1-BD5F-8D2DDF33CFBD}</Project>
|
||||
<Name>Lidgren.Network</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
63
Samples/BarebonesServer/Program.cs
Normal file
63
Samples/BarebonesServer/Program.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
using Lidgren.Network;
|
||||
|
||||
namespace BarebonesServer
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
NetPeerConfiguration config = new NetPeerConfiguration("barebones");
|
||||
config.Port = 14242;
|
||||
config.SimulatedLoss = 0.1f;
|
||||
NetServer server = new NetServer(config);
|
||||
server.Start();
|
||||
|
||||
NetIncomingMessage inc;
|
||||
while (Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
|
||||
{
|
||||
while ((inc = server.ReadMessage()) != null)
|
||||
{
|
||||
switch (inc.MessageType)
|
||||
{
|
||||
case NetIncomingMessageType.DebugMessage:
|
||||
case NetIncomingMessageType.VerboseDebugMessage:
|
||||
case NetIncomingMessageType.WarningMessage:
|
||||
case NetIncomingMessageType.ErrorMessage:
|
||||
Console.WriteLine(inc.ReadString());
|
||||
break;
|
||||
case NetIncomingMessageType.StatusChanged:
|
||||
NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte();
|
||||
string reason = inc.ReadString();
|
||||
Console.WriteLine("New status: " + status + " (" + reason + ")");
|
||||
break;
|
||||
case NetIncomingMessageType.UnconnectedData:
|
||||
Console.WriteLine("Received unconnected data from " + inc.SenderEndpoint + ", conn is " + inc.SenderConnection);
|
||||
break;
|
||||
case NetIncomingMessageType.Data:
|
||||
Console.WriteLine("Received " + inc.LengthBytes + " bytes of data from " + inc.SenderConnection + ", endpoint is " + inc.SenderEndpoint);
|
||||
|
||||
// temporary code to verify issue with large messages
|
||||
StringBuilder bdr = new StringBuilder();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
bdr.Append("Hallonsmurf" + i.ToString());
|
||||
|
||||
string str = inc.ReadString();
|
||||
|
||||
Console.WriteLine("Compare gives: " + str.CompareTo(bdr.ToString()));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
Console.WriteLine("Application exiting");
|
||||
while (true) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Samples/BarebonesServer/Properties/AssemblyInfo.cs
Normal file
36
Samples/BarebonesServer/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("BarebonesServer")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("BarebonesServer")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f0faed82-6c17-41dc-a45e-c9534a29eff8")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user