diff --git a/TCP.AsynClient/Client/Client.csproj b/TCP.AsynClient/Client/Client.csproj new file mode 100644 index 0000000..522b318 --- /dev/null +++ b/TCP.AsynClient/Client/Client.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp2.2 + + + + + + + diff --git a/TCP.AsynClient/Client/Program.cs b/TCP.AsynClient/Client/Program.cs new file mode 100644 index 0000000..bfb81ce --- /dev/null +++ b/TCP.AsynClient/Client/Program.cs @@ -0,0 +1,34 @@ +using BeetleX; +using BeetleX.Clients; +using System; +using System.Net; + +namespace Client +{ + class Program + { + static void Main(string[] args) + { + AsyncTcpClient client = SocketFactory.CreateClient("127.0.0.1", 9090); + client.DataReceive = (o, e) => + { + var pipestream = e.Stream.ToPipeStream(); + if (pipestream.TryReadLine(out string line)) + { + Console.WriteLine(line); + } + }; + while (true) + { + Console.Write("Enter Name:"); + BytesHandler line = Console.ReadLine() + "\r\n"; + client.Send(line); + if(!client.IsConnected) + { + Console.WriteLine(client.LastError.Message); + } + } + + } + } +} diff --git a/TCP.AsynClient/Server/Program.cs b/TCP.AsynClient/Server/Program.cs new file mode 100644 index 0000000..dd7485e --- /dev/null +++ b/TCP.AsynClient/Server/Program.cs @@ -0,0 +1,30 @@ +using BeetleX; +using BeetleX.EventArgs; +using System; + +namespace Server +{ + class Program : ServerHandlerBase + { + private static IServer server; + public static void Main(string[] args) + { + server = SocketFactory.CreateTcpServer(); + //server.Options.DefaultListen.Port =9090; + //server.Options.DefaultListen.Host = "127.0.0.1"; + server.Open(); + Console.Read(); + } + public override void SessionReceive(IServer server, SessionReceiveEventArgs e) + { + var pipeStream = e.Stream.ToPipeStream(); + if (pipeStream.TryReadLine(out string name)) + { + Console.WriteLine(name); + e.Session.Stream.ToPipeStream().WriteLine("hello " + name); + e.Session.Stream.Flush(); + } + base.SessionReceive(server, e); + } + } +} diff --git a/TCP.AsynClient/Server/Server.csproj b/TCP.AsynClient/Server/Server.csproj new file mode 100644 index 0000000..522b318 --- /dev/null +++ b/TCP.AsynClient/Server/Server.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp2.2 + + + + + + + diff --git a/TCP.AsynClient/TCP.AsynClient.sln b/TCP.AsynClient/TCP.AsynClient.sln new file mode 100644 index 0000000..8608139 --- /dev/null +++ b/TCP.AsynClient/TCP.AsynClient.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.705 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Server\Server.csproj", "{01636360-991A-43DE-8C32-78C00D5C7406}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "Client\Client.csproj", "{7C8A6B33-57CF-4FA0-B855-E6411C378194}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {01636360-991A-43DE-8C32-78C00D5C7406}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {01636360-991A-43DE-8C32-78C00D5C7406}.Debug|Any CPU.Build.0 = Debug|Any CPU + {01636360-991A-43DE-8C32-78C00D5C7406}.Release|Any CPU.ActiveCfg = Release|Any CPU + {01636360-991A-43DE-8C32-78C00D5C7406}.Release|Any CPU.Build.0 = Release|Any CPU + {7C8A6B33-57CF-4FA0-B855-E6411C378194}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C8A6B33-57CF-4FA0-B855-E6411C378194}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C8A6B33-57CF-4FA0-B855-E6411C378194}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C8A6B33-57CF-4FA0-B855-E6411C378194}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A2A9DF2D-E003-4BEB-A5F3-B3B46279390B} + EndGlobalSection +EndGlobal