From a7b4fc7be6dac8c4ff9ae7924eb499d7e2ac1453 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Tue, 10 Oct 2017 11:21:01 +0200 Subject: Removed packages, added Client project properly. --- Client/Client.csproj | 61 +++++++++++++ Client/MainWindow.cs | 35 +++++++ Client/Program.cs | 16 ++++ Client/Properties/AssemblyInfo.cs | 26 ++++++ Client/TcpChatClient.cs | 69 ++++++++++++++ Client/gtk-gui/MainWindow.cs | 179 ++++++++++++++++++++++++++++++++++++ Client/gtk-gui/generated.cs | 30 ++++++ Client/gtk-gui/gui.stetic | 187 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 603 insertions(+) create mode 100644 Client/Client.csproj create mode 100644 Client/MainWindow.cs create mode 100644 Client/Program.cs create mode 100644 Client/Properties/AssemblyInfo.cs create mode 100644 Client/TcpChatClient.cs create mode 100644 Client/gtk-gui/MainWindow.cs create mode 100644 Client/gtk-gui/generated.cs create mode 100644 Client/gtk-gui/gui.stetic (limited to 'Client') diff --git a/Client/Client.csproj b/Client/Client.csproj new file mode 100644 index 0000000..f0d2993 --- /dev/null +++ b/Client/Client.csproj @@ -0,0 +1,61 @@ + + + + {73154F68-BBEB-48FC-86C4-BB4909C1C7B4} + WinExe + v4.5 + Client + Client + + + true + full + false + bin\Debug + DEBUG; + 4 + x86 + + + true + bin\Release + 4 + x86 + + + + + False + + + False + + + False + + + False + + + False + + + False + + + + + + gui.stetic + + + + + + + + + + + + \ No newline at end of file diff --git a/Client/MainWindow.cs b/Client/MainWindow.cs new file mode 100644 index 0000000..22564ac --- /dev/null +++ b/Client/MainWindow.cs @@ -0,0 +1,35 @@ +using System; +using Gtk; +using Client; + +public partial class MainWindow : Gtk.Window +{ + TcpChatClient tcpChat; + + public MainWindow() : base(Gtk.WindowType.Toplevel) + { + Build(); + tcpChat = new TcpChatClient(); + tcpChat.PropertyChanged += (sender, args) => + outputTv.Buffer.Text = tcpChat.Log; + } + + protected void OnDeleteEvent(object sender, DeleteEventArgs a) + { + Application.Quit(); + a.RetVal = true; + } + + protected async void Connect(object sender, EventArgs e) + { + await tcpChat.Connect(ipEntry.Text, Int32.Parse(portEntry.Text)); + tcpChat.SendMessage($"{usernameEntry.Text} connected."); + } + + protected void SendMessage(object sender, EventArgs e) + { + string message = $"{usernameEntry.Text}: {messageEntry.Text}"; + tcpChat.SendMessage(message); + messageEntry.Text = ""; + } +} diff --git a/Client/Program.cs b/Client/Program.cs new file mode 100644 index 0000000..22bf2bb --- /dev/null +++ b/Client/Program.cs @@ -0,0 +1,16 @@ +using System; +using Gtk; + +namespace Client +{ + class MainClass + { + public static void Main(string[] args) + { + Application.Init(); + MainWindow win = new MainWindow(); + win.Show(); + Application.Run(); + } + } +} diff --git a/Client/Properties/AssemblyInfo.cs b/Client/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7614f1a --- /dev/null +++ b/Client/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("Client")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("${AuthorCopyright}")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/Client/TcpChatClient.cs b/Client/TcpChatClient.cs new file mode 100644 index 0000000..e9d4b54 --- /dev/null +++ b/Client/TcpChatClient.cs @@ -0,0 +1,69 @@ +using System; +using System.ComponentModel; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; + +namespace Client +{ + public class TcpChatClient : INotifyPropertyChanged + { + public int Port { get; set; } + + private string log; + public string Log + { + get + { + return log; + } + set + { + log = value; + OnPropertyChanged(); + } + } + public bool Status { get; set; } + private StreamReader sr; + private StreamWriter sw; + + public TcpChatClient() + { + } + + public async Task Connect(string ipAddress, int port) + { + TcpClient clientSocket = new TcpClient(ipAddress, port); + NetworkStream ns = clientSocket.GetStream(); + sr = new StreamReader(ns); + sw = new StreamWriter(ns); + sw.AutoFlush = true; + Status = true; + await ReceiveMessageAsync(); + } + + public void SendMessage(string message) + { + sw.WriteLine(message); + } + + private async T