From 295e3c10bb6d1c83796554edf8369e5aa87a20a8 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Mon, 9 Oct 2017 08:56:25 +0200 Subject: Initial commit. --- Server/App.cs | 10 +++ Server/ClientConnection.cs | 34 +++++++++ Server/LogSingleton.cs | 40 +++++++++++ Server/MainWindow.cs | 76 +++++++++++++++++++++ Server/Program.cs | 19 ++++++ Server/Server.csproj | 50 ++++++++++++++ Server/TcpChatServer.cs | 50 ++++++++++++++ Server/bin/Debug/Eto.Gtk2.dll | Bin 0 -> 314368 bytes Server/bin/Debug/Eto.Gtk3.dll | Bin 0 -> 323584 bytes Server/bin/Debug/Eto.dll | Bin 0 -> 502784 bytes Server/bin/Debug/Server.exe | Bin 0 -> 10752 bytes Server/bin/Debug/Server.pdb | Bin 0 -> 2668 bytes Server/bin/Debug/Xwt.Gtk.dll | Bin 0 -> 286720 bytes Server/bin/Debug/Xwt.Gtk.dll.config | 22 ++++++ Server/bin/Debug/Xwt.dll | Bin 0 -> 414720 bytes Server/bin/Debug/atk-sharp.dll.config | 8 +++ Server/bin/Debug/gdk-sharp.dll.config | 14 ++++ Server/bin/Debug/gio-sharp.dll.config | 10 +++ Server/bin/Debug/glib-sharp.dll.config | 8 +++ Server/bin/Debug/gtk-dotnet.dll.config | 5 ++ Server/bin/Debug/gtk-sharp.dll.config | 12 ++++ Server/bin/Debug/pango-sharp.dll.config | 12 ++++ ....NETFramework,Version=v4.5.AssemblyAttribute.cs | 2 + Server/obj/x86/Debug/Server.csproj.CopyComplete | 0 .../Debug/Server.csproj.CoreCompileInputs.cache | 1 + .../x86/Debug/Server.csproj.FileListAbsolute.txt | 9 +++ .../Debug/Server.csproj.FilesWrittenAbsolute.txt | 13 ++++ .../Server.csprojResolveAssemblyReference.cache | Bin 0 -> 72279 bytes Server/obj/x86/Debug/Server.exe | Bin 0 -> 10752 bytes Server/obj/x86/Debug/Server.pdb | Bin 0 -> 2668 bytes Server/packages.config | 5 ++ 31 files changed, 400 insertions(+) create mode 100644 Server/App.cs create mode 100644 Server/ClientConnection.cs create mode 100644 Server/LogSingleton.cs create mode 100644 Server/MainWindow.cs create mode 100644 Server/Program.cs create mode 100644 Server/Server.csproj create mode 100644 Server/TcpChatServer.cs create mode 100644 Server/bin/Debug/Eto.Gtk2.dll create mode 100644 Server/bin/Debug/Eto.Gtk3.dll create mode 100644 Server/bin/Debug/Eto.dll create mode 100644 Server/bin/Debug/Server.exe create mode 100644 Server/bin/Debug/Server.pdb create mode 100644 Server/bin/Debug/Xwt.Gtk.dll create mode 100644 Server/bin/Debug/Xwt.Gtk.dll.config create mode 100644 Server/bin/Debug/Xwt.dll create mode 100644 Server/bin/Debug/atk-sharp.dll.config create mode 100644 Server/bin/Debug/gdk-sharp.dll.config create mode 100644 Server/bin/Debug/gio-sharp.dll.config create mode 100644 Server/bin/Debug/glib-sharp.dll.config create mode 100644 Server/bin/Debug/gtk-dotnet.dll.config create mode 100644 Server/bin/Debug/gtk-sharp.dll.config create mode 100644 Server/bin/Debug/pango-sharp.dll.config create mode 100644 Server/obj/x86/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs create mode 100644 Server/obj/x86/Debug/Server.csproj.CopyComplete create mode 100644 Server/obj/x86/Debug/Server.csproj.CoreCompileInputs.cache create mode 100644 Server/obj/x86/Debug/Server.csproj.FileListAbsolute.txt create mode 100644 Server/obj/x86/Debug/Server.csproj.FilesWrittenAbsolute.txt create mode 100644 Server/obj/x86/Debug/Server.csprojResolveAssemblyReference.cache create mode 100644 Server/obj/x86/Debug/Server.exe create mode 100644 Server/obj/x86/Debug/Server.pdb create mode 100644 Server/packages.config (limited to 'Server') diff --git a/Server/App.cs b/Server/App.cs new file mode 100644 index 0000000..8d02d69 --- /dev/null +++ b/Server/App.cs @@ -0,0 +1,10 @@ +sing System; +namespace Server +{ + public class App + { + public App() + { + } + } +} diff --git a/Server/ClientConnection.cs b/Server/ClientConnection.cs new file mode 100644 index 0000000..f2d8976 --- /dev/null +++ b/Server/ClientConnection.cs @@ -0,0 +1,34 @@ +using System; +using System.IO; +using System.Net.Sockets; +using System.Threading.Tasks; + +namespace Server +{ + public class ClientConnection + { + public StreamReader StreamReader { get; set; } + public StreamWriter StreamWriter { get; set; } + + public ClientConnection(TcpListener listener) + { + TcpClient connectionSocket = listener.AcceptTcpClient(); + NetworkStream ns = connectionSocket.GetStream(); + StreamReader = new StreamReader(ns); + StreamWriter = new StreamWriter(ns); + StreamWriter.AutoFlush = true; + Task.Run(() => EchoService(StreamReader, StreamWriter)); + } + + private async Task EchoService(StreamReader sr, StreamWriter sw) + { + while (true) + { + string message = await sr.ReadLineAsync(); + LogSingleton.Instance.Log += $"{message}\n"; + foreach (ClientConnection client in LogSingleton.Instance.ConnectedClients) client.StreamWriter.WriteLine(message); + message = ""; + } + } + } +} diff --git a/Server/LogSingleton.cs b/Server/LogSingleton.cs new file mode 100644 index 0000000..158440d --- /dev/null +++ b/Server/LogSingleton.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace Server +{ + public class LogSingleton : INotifyPropertyChanged + { + private static LogSingleton _instance; + public static LogSingleton Instance => _instance ?? (_instance = new LogSingleton()); + + private string log; + public string Log + { + get + { + return log; + } + set + { + log = value; + OnPropertyChanged(); + } + } + + public List ConnectedClients { get; set; } + + private LogSingleton() + { + ConnectedClients = new List(); + } + + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/Server/MainWindow.cs b/Server/MainWindow.cs new file mode 100644 index 0000000..e8974d2 --- /dev/null +++ b/Server/MainWindow.cs @@ -0,0 +1,76 @@ +using System; +using Xwt; +using Xwt.Formats; + +namespace Server +{ + public class MainWindow : Window + { + TcpChatServer tcpChatServer; + + public MainWindow() + { + Title = "TCP Chat X Server"; + Width = 600; + Height = 400; + + VBox mainVBox; + HBox connectionHBox, messageHBox; + TextEntry ipTextEntry = new TextEntry + { + PlaceholderText = "IP Address", + Text = "127.0.0.1", + }; + TextEntry portTextEntry = new TextEntry + { + WidthRequest = 100, + PlaceholderText = "Port", + Text = "6789" + }; + Button startButton = new Button + { + Label = "Start" + }; + startButton.Clicked += (object sender, EventArgs e) => + { + tcpChatServer = new TcpChatServer(); + tcpChatServer.Start(ipTextEntry.Text, int.Parse(portTextEntry.Text)); + }; + RichTextView outputTextView = new RichTextView + { + ExpandHorizontal = true, + ExpandVertical = true, + MinHeight = 200 + }; + LogSingleton.Instance.PropertyChanged += (sender, args) => + outputTextView.LoadText(LogSingleton.Instance.Log, TextFormat.Plain); + + TextEntry messageTextEntry = new TextEntry() + { + PlaceholderText = "Message" + }; + Button sendButton = new Button + { + Label = "Send" + }; + sendButton.Clicked += (object sender, EventArgs e) => + { + tcpChatServer.SendMessage($"Server: {messageTextEntry.Text}"); + messageTextEntry.Text = ""; + }; + + Content = mainVBox = new VBox(); + + mainVBox.PackStart(connectionHBox = new HBox()); + connectionHBox.PackStart(ipTextEntry , true); + connectionHBox.PackStart(portTextEntry); + connectionHBox.PackStart(startButton); + + mainVBox.PackStart(outputTextView, true, true); + + mainVBox.PackStart(messageHBox = new HBox()); + messageHBox.PackStart(messageTextEntry, true, true); + messageHBox.PackStart(sendButton); + } + } +} diff --git a/Server/Program.cs b/Server/Program.cs new file mode 100644 index 0000000..35bf5e4 --- /dev/null +++ b/Server/Program.cs @@ -0,0 +1,19 @@ +using System; +using Xwt; + +namespace Server +{ + class Program + { + [STAThread] + static void Main() + { + Application.Initialize(); + var mainWindow = new MainWindow(); + mainWindow.Show(); + Application.Run(); + mainWindow.Dispose(); + } + } + +} diff --git a/Server/Server.csproj b/Server/Server.csproj new file mode 100644 index 0000000..5b68532 --- /dev/null +++ b/Server/Server.csproj @@ -0,0 +1,50 @@ + + + + + Debug + x86 + {8CB98A13-75A8-42B1-9E03-4FA3ABCEAA3B} + Exe + Server + Server + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 + + + true + bin\Release + prompt + 4 + x86 + + + + + + + + + + + + ..\packages\Xwt.0.2.40\lib\net40\Xwt.dll + + + ..\packages\Xwt.Gtk.0.2.40\lib\net40\Xwt.Gtk.dll + + + + + + + \ No newline at end of file diff --git a/Server/TcpChatServer.cs b/Server/TcpChatServer.cs new file mode 100644 index 0000000..986bbf1 --- /dev/null +++ b/Server/TcpChatServer.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Threading.Tasks; + +namespace Server +{ + public class TcpChatServer + { + TcpListener serverSocket; + + public void Start(string ipAddress, int port) + { + try + { + serverSocket = new TcpListener(IPAddress.Parse(ipAddress), port); + serverSocket.Start(); + LogSingleton.Instance.Log += "Server started.\n"; + Task.Run(() => Listen(serverSocket)); + LogSingleton.Instance.Log += "Waiting for connections...\n"; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + + private void Listen(TcpListener listener) + { + while (true) + { + ClientConnection cc = new ClientConnection(listener); + LogSingleton.Instance.ConnectedClients.Add(cc); + } + } + + public void Stop() + { + serverSocket.Stop(); + LogSingleton.Instance.Log += "Server stopped\n"; + } + + public void SendMessage(string message) + { + foreach (ClientConnection client in LogSingleton.Instance.ConnectedClients) client.StreamWriter.WriteLine(message); + } + } +} diff --git a/Server/bin/Debug/Eto.Gtk2.dll b/Server/bin/Debug/Eto.Gtk2.dll new file mode 100644 index 0000000..c0fddb7 Binary files /dev/null and b/Server/bin/Debug/Eto.Gtk2.dll differ diff --git a/Server/bin/Debug/Eto.Gtk3.dll b/Server/bin/Debug/Eto.Gtk3.dll new file mode 100644 index 0000000..21bbb3d Binary files /dev/null and b/Server/bin/Debug/Eto.Gtk3.dll differ diff --git a/Server/bin/Debug/Eto.dll b/Server/bin/Debug/Eto.dll new file mode 100644 index 0000000..306ef1d Binary files /dev/null and b/Server/bin/Debug/Eto.dll differ diff --git a/Server/bin/Debug/Server.exe b/Server/bin/Debug/Server.exe new file mode 100644 index 0000000..482894d Binary files /dev/null and b/Server/bin/Debug/Server.exe differ diff --git a/Server/bin/Debug/Server.pdb b/Server/bin/Debug/Server.pdb new file mode 100644 index 0000000..a70dc58 Binary files /dev/null and b/Server/bin/Debug/Server.pdb differ diff --git a/Server/bin/Debug/Xwt.Gtk.dll b/Server/bin/Debug/Xwt.Gtk.dll new file mode 100644 index 0000000..b80892c Binary files /dev/null and b/Server/bin/Debug/Xwt.Gtk.dll differ diff --git a/Server/bin/Debug/Xwt.Gtk.dll.config b/Server/bin/Debug/Xwt.Gtk.dll.config new file mode 100644 index 0000000..f1630bb --- /dev/null +++ b/Server/bin/Debug/Xwt.Gtk.dll.config @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Server/bin/Debug/Xwt.dll b/Server/bin/Debug/Xwt.dll new file mode 100644 index 0000000..c50a574 Binary files /dev/null and b/Server/bin/Debug/Xwt.dll differ diff --git a/Server/bin/Debug/atk-sharp.dll.config b/Server/bin/Debug/atk-sharp.dll.config new file mode 100644 index 0000000..671f620 --- /dev/null +++ b/Server/bin/Debug/atk-sharp.dll.config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Server/bin/Debug/gdk-sharp.dll.config b/Server/bin/Debug/gdk-sharp.dll.config new file mode 100644 index 0000000..00917fd --- /dev/null +++ b/Server/bin/Debug/gdk-sharp.dll.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/Server/bin/Debug/gio-sharp.dll.config b/Server/bin/Debug/gio-sharp.dll.config new file mode 100644 index 0000000..47c0700 --- /dev/null +++ b/Server/bin/Debug/gio-sharp.dll.config @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Server/bin/Debug/glib-sharp.dll.config b/Server/bin/Debug/glib-sharp.dll.config new file mode 100644 index 0000000..2fd9ec4 --- /dev/null +++ b/Server/bin/Debug/glib-sharp.dll.config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Server/bin/Debug/gtk-dotnet.dll.config b/Server/bin/Debug/gtk-dotnet.dll.config new file mode 100644 index 0000000..ebd8040 --- /dev/null +++ b/Server/bin/Debug/gtk-dotnet.dll.config @@ -0,0 +1,5 @@ + + + + + diff --git a/Server/bin/Debug/gtk-sharp.dll.config b/Server/bin/Debug/gtk-sharp.dll.config new file mode 100644 index 0000000..2914bb7 --- /dev/null +++ b/Server/bin/Debug/gtk-sharp.dll.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Server/bin/Debug/pango-sharp.dll.config b/Server/bin/Debug/pango-sharp.dll.config new file mode 100644 index 0000000..2ec8168 --- /dev/null +++ b/Server/bin/Debug/pango-sharp.dll.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Server/obj/x86/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs b/Server/obj/x86/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs new file mode 100644 index 0000000..fdcb678 --- /dev/null +++ b/Server/obj/x86/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs @@ -0,0 +1,2 @@ +// +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5", FrameworkDisplayName = "")] diff --git a/Server/obj/x86/Debug/Server.csproj.CopyComplete b/Server/obj/x86/Debug/Server.csproj.CopyComplete new file mode 100644 index 0000000..e69de29 diff --git a/Server/obj/x86/Debug/Server.csproj.CoreCompileInputs.cache b/Server/obj/x86/Debug/Server.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..b760382 --- /dev/null +++ b/Server/obj/x86/Debug/Server.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +288dbf2ed052e53bd705274b9a599fcb3c80460a diff --git a/Server/obj/x86/Debug/Server.csproj.FileListAbsolute.txt b/Server/obj/x86/Debug/Server.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..531304f --- /dev/null +++ b/Server/obj/x86/Debug/Server.csproj.FileListAbsolute.txt @@ -0,0 +1,9 @@ +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Server.exe +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Server.pdb +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Xwt.dll +/home/marcin/MonoDevelop Projects/TcpChatX/Server/obj/x86/Debug/Server.csproj.CoreCompileInputs.cache +/home/marcin/MonoDevelop Projects/TcpChatX/Server/obj/x86/Debug/Server.exe +/home/marcin/MonoDevelop Projects/TcpChatX/Server/obj/x86/Debug/Server.pdb +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Xwt.Gtk.dll.config +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Xwt.Gtk.dll +/home/marcin/MonoDevelop Projects/TcpChatX/Server/obj/x86/Debug/Server.csprojResolveAssemblyReference.cache diff --git a/Server/obj/x86/Debug/Server.csproj.FilesWrittenAbsolute.txt b/Server/obj/x86/Debug/Server.csproj.FilesWrittenAbsolute.txt new file mode 100644 index 0000000..5ab07d3 --- /dev/null +++ b/Server/obj/x86/Debug/Server.csproj.FilesWrittenAbsolute.txt @@ -0,0 +1,13 @@ +/home/marcin/MonoDevelop Projects/TcpChatX/Server/obj/x86/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Eto.dll +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Eto.Gtk3.dll +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Server.pdb +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Server.exe +/home/marcin/MonoDevelop Projects/TcpChatX/Server/obj/x86/Debug/Server.exe +/home/marcin/MonoDevelop Projects/TcpChatX/Server/obj/x86/Debug/Server.pdb +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Eto.Gtk2.dll +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Xwt.Gtk.dll.config +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Xwt.dll +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Xwt.Gtk.dll +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Xwt.WPF.dll +/home/marcin/MonoDevelop Projects/TcpChatX/Server/bin/Debug/Xwt.Gtk.Windows.dll diff --git a/Server/obj/x86/Debug/Server.csprojResolveAssemblyReference.cache b/Server/obj/x86/Debug/Server.csprojResolveAssemblyReference.cache new file mode 100644 index 0000000..0cdf7de Binary files /dev/null and b/Server/obj/x86/Debug/Server.csprojResolveAssemblyReference.cache differ diff --git a/Server/obj/x86/Debug/Server.exe b/Server/obj/x86/Debug/Server.exe new file mode 100644 index 0000000..482894d Binary files /dev/null and b/Server/obj/x86/Debug/Server.exe differ diff --git a/Server/obj/x86/Debug/Server.pdb b/Server/obj/x86/Debug/Server.pdb new file mode 100644 index 0000000..a70dc58 Binary files /dev/null and b/Server/obj/x86/Debug/Server.pdb differ diff --git a/Server/packages.config b/Server/packages.config new file mode 100644 index 0000000..5714f0f --- /dev/null +++ b/Server/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file -- cgit v1.2.3