}
Assert.AreEqual(sendOption, args.SendOption);
-
+
mutex.Set();
};
//Setup meta stuff
byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
ManualResetEvent mutex = new ManualResetEvent(false);
+ ManualResetEvent mutex2 = new ManualResetEvent(false);
//Setup listener
listener.NewConnection += delegate(object sender, NewConnectionEventArgs args)
Assert.AreEqual(0, args.Connection.Statistics.TotalBytesSent);
Assert.AreEqual(data.Length + headerSize, args.Connection.Statistics.TotalBytesReceived);
- mutex.Set();
+ mutex2.Set();
};
+
+ mutex.Set();
};
listener.Start();
//Connect
connection.Connect();
+
+ mutex.WaitOne();
+
connection.SendBytes(data, sendOption);
//Wait until data is received
- mutex.WaitOne();
+ mutex2.WaitOne();
Assert.AreEqual(data.Length, connection.Statistics.DataBytesSent);
Assert.AreEqual(0, connection.Statistics.DataBytesReceived);
internal static void RunClientDisconnectTest(ConnectionListener listener, Connection connection)
{
ManualResetEvent mutex = new ManualResetEvent(false);
+ ManualResetEvent mutex2 = new ManualResetEvent(false);
listener.NewConnection += delegate(object sender, NewConnectionEventArgs args)
{
args.Connection.Disconnected += delegate(object sender2, DisconnectedEventArgs args2)
{
- mutex.Set();
+ mutex2.Set();
};
+
+ mutex.Set();
};
listener.Start();
connection.Connect();
+ mutex.WaitOne();
+
connection.Close();
- mutex.WaitOne();
+ mutex2.WaitOne();
}
}
}
/// Tests dual mode connectivity.
/// </summary>
[TestMethod]
- public void TcpDualModeConnectionTest()
+ public void UdpDualModeConnectionTest()
{
using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296, IPMode.IPv4AndIPv6))
{
System.Threading.Thread.Sleep(1100); //Enough time for ~10 keep alive packets
Assert.IsTrue(
- connection.Statistics.TotalBytesSent >= 27
- && connection.Statistics.TotalBytesSent <= 33,
- "Received: " + connection.Statistics.TotalBytesSent
+ connection.Statistics.TotalBytesSent >= 27 &&
+ connection.Statistics.TotalBytesSent <= 33,
+ "Sent: " + connection.Statistics.TotalBytesSent
);
}
}
Thread.Sleep(1100); //Enough time for ~10 keep alive packets
Assert.IsTrue(
- args.Connection.Statistics.TotalBytesSent >= 27
- && args.Connection.Statistics.TotalBytesSent <= 33,
- "Received: " + args.Connection.Statistics.TotalBytesSent
+ args.Connection.Statistics.TotalBytesSent >= 27 &&
+ args.Connection.Statistics.TotalBytesSent <= 33,
+ "Sent: " + connection.Statistics.TotalBytesSent
);
mutex.Set();
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+ </startup>
+</configuration>
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using Hazel;
+using Hazel.Udp;
+
+namespace HazelExample
+{
+ class ClientExample
+ {
+ static Connection connection;
+
+ public static void Main(string[] args)
+ {
+ NetworkEndPoint endPoint = new NetworkEndPoint("13.74.185.0", 4296);
+
+ connection = new UdpClientConnection(endPoint);
+
+ connection.DataReceived += DataReceived;
+
+ Console.WriteLine("Connecting!");
+
+ connection.Connect();
+
+ connection.SendBytes(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
+
+ Console.WriteLine("Press any key to continue...");
+
+ Console.ReadKey();
+
+ connection.Close();
+ }
+
+ private static void DataReceived(object sender, DataReceivedEventArgs args)
+ {
+ Console.WriteLine("Received (" + string.Join<byte>(", ", args.Bytes) + ") from " + connection.EndPoint.ToString());
+
+ args.Recycle();
+ }
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{F869A12F-7E4A-4DDA-AD96-A226E4923859}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>HazelTest</RootNamespace>
+ <AssemblyName>HazelTest</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <PublishUrl>publish\</PublishUrl>
+ <Install>true</Install>
+ <InstallFrom>Disk</InstallFrom>
+ <UpdateEnabled>false</UpdateEnabled>
+ <UpdateMode>Foreground</UpdateMode>
+ <UpdateInterval>7</UpdateInterval>
+ <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+ <UpdatePeriodically>false</UpdatePeriodically>
+ <UpdateRequired>false</UpdateRequired>
+ <MapFileExtensions>true</MapFileExtensions>
+ <ApplicationRevision>0</ApplicationRevision>
+ <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
+ <UseApplicationTrust>false</UseApplicationTrust>
+ <BootstrapperEnabled>true</BootstrapperEnabled>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <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' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <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" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ClientExample.cs" />
+ <Compile Include="ServerExample.cs" />
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Hazel\Hazel.csproj">
+ <Project>{02cfbd30-d77d-400f-94b2-700f60efdd7f}</Project>
+ <Name>Hazel</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <BootstrapperPackage Include=".NETFramework,Version=v4.5">
+ <Visible>False</Visible>
+ <ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
+ <Install>true</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+ <Visible>False</Visible>
+ <ProductName>.NET Framework 3.5 SP1</ProductName>
+ <Install>false</Install>
+ </BootstrapperPackage>
+ </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>
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+
+using Hazel.Udp;
+
+namespace Hazel
+{
+ class Program
+ {
+ static void Main2(string[] args)
+ {
+ /*using (Connection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
+ {
+ connection.Connect();
+ connection.DataReceived += connection_DataReceived;
+ connection.Disconnected += connection_Disconnected;
+
+ while (Console.ReadLine() != "Quit")
+ connection.SendBytes(new byte[] { 0, 1, 2, 3, 4 }, SendOption.Reliable);
+ }*/
+
+ /*using (ConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296, IPMode.IPv4))
+ {
+ listener.NewConnection += delegate(object sender, NewConnectionEventArgs a)
+ {
+ Console.WriteLine("Hi! " + a.Connection.EndPoint.ToString());
+
+ a.Connection.DataReceived += delegate(object sender2, DataEventArgs a2)
+ {
+ Console.WriteLine("Received " + a2.Bytes.Length + " of data!");
+ a.Connection.SendBytes(a2.Bytes, a2.SendOption);
+ };
+
+ a.Connection.Disconnected += connection_Disconnected;
+ };
+
+ listener.Start();
+
+ Console.ReadKey();
+ }*/
+ }
+
+ static void connection_DataReceived(object sender, DataReceivedEventArgs e)
+ {
+ Console.WriteLine(e.Bytes.Length);
+ }
+
+ static void connection_Disconnected(object sender, DisconnectedEventArgs e)
+ {
+ Console.WriteLine("Bye Bye!");
+ }
+ }
+}
--- /dev/null
+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("HazelTest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("HazelTest")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[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("403a5501-7047-43f5-84df-822ac7dcf00d")]
+
+// 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")]
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Net;
+
+using Hazel;
+using Hazel.Tcp;
+/*
+namespace HazelExample
+{
+ class ServerExample
+ {
+ static ConnectionListener listener;
+
+ public static void Main(string[] args)
+ {
+ listener = new TcpConnectionListener(IPAddress.Any, 4296);
+
+ listener.NewConnection += NewConnectionHandler;
+
+ Console.WriteLine("Starting server!");
+
+ listener.Start();
+
+ Console.WriteLine("Press any key to continue...");
+
+ Console.ReadKey();
+
+ listener.Close();
+ }
+
+ static void NewConnectionHandler(object sender, NewConnectionEventArgs args)
+ {
+ Console.WriteLine("New connection from " + args.Connection.EndPoint.ToString());
+
+ args.Connection.DataReceived += DataReceivedHandler;
+
+ args.Recycle();
+ }
+
+ private static void DataReceivedHandler(object sender, DataEventArgs args)
+ {
+ Connection connection = (Connection)sender;
+
+ Console.WriteLine("Received (" + string.Join<byte>(", ", args.Bytes) + ") from " + connection.EndPoint.ToString());
+
+ connection.SendBytes(args.Bytes, args.SendOption);
+
+ args.Recycle();
+ }
+ }
+}
+*/
\ No newline at end of file