diff --git a/chatclient/App.config b/chatclient/App.config new file mode 100644 index 0000000..964a4fb --- /dev/null +++ b/chatclient/App.config @@ -0,0 +1,7 @@ + + + +
+ + + \ No newline at end of file diff --git a/chatclient/App.xaml b/chatclient/App.xaml new file mode 100644 index 0000000..76fd1be --- /dev/null +++ b/chatclient/App.xaml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/chatclient/App.xaml.cs b/chatclient/App.xaml.cs new file mode 100644 index 0000000..ff1f313 --- /dev/null +++ b/chatclient/App.xaml.cs @@ -0,0 +1,14 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace chatclient +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } + +} diff --git a/chatclient/AssemblyInfo.cs b/chatclient/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/chatclient/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/chatclient/LoginWindow.xaml b/chatclient/LoginWindow.xaml new file mode 100644 index 0000000..1fe658d --- /dev/null +++ b/chatclient/LoginWindow.xaml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/chatclient/MainWindow.xaml.cs b/chatclient/MainWindow.xaml.cs new file mode 100644 index 0000000..fc1b358 --- /dev/null +++ b/chatclient/MainWindow.xaml.cs @@ -0,0 +1,183 @@ +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +<<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> 添加基础功能 +using System.Net.Sockets; +using System.Net; +using System.IO; +using System; +using System.Security.Policy; +using log4net; +using log4net.Config; +<<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> 添加登录ui以及部分交互逻辑 +using System.Text.Json; +using chatapi; +using System.Diagnostics; +using System.Windows.Interop; +using ControlzEx.Standard; +<<<<<<< HEAD +======= +>>>>>>> 添加基础功能 + +[assembly: XmlConfigurator(ConfigFile = "config/log4net.config", Watch = true)] +======= + +>>>>>>> 添加项目文件。 +======= + +[assembly: XmlConfigurator(ConfigFile = "config/log4net.config", Watch = true)] +>>>>>>> 添加登录ui以及部分交互逻辑 +namespace chatclient +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { +<<<<<<< HEAD +<<<<<<< HEAD +<<<<<<< HEAD + LoginWindow Login = new(); + static string? receive; + public static int user_id = 0; + public static string? LoginMsg = "123"; + private static readonly ILog log = LogManager.GetLogger(typeof(MainWindow)); + public static Socket? Client; + public MainWindow() + { + InitializeComponent(); + log.Info("Hello World!"); + this.Hide(); + Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + try + { + log.Info("连接服务器 127.0.0.1:5555 "); + Client.Connect("127.0.0.1", 5555); + } + catch (Exception ex) + { + Client.Close(); + log.Error(ex); + } + Login.Show(); + Thread th = new Thread(Receive); + th.Start(); + } + static void Receive() + { + byte[] buffer = new byte[1024]; + try + { + while (true) + { + int num = Client!.Receive(buffer); + if (num == 0) break; + if (Client.Poll(100, SelectMode.SelectRead) && Client.Available == 0 || !Client.Connected) + { + log.Error("连接已断开"); + break; + } + receive = Encoding.UTF8.GetString(buffer, 0, num); + response(receive); + } + } + catch (Exception ex) { + log.Error(ex); + } + finally + { + Client?.Close(); + } + } + static void response(string msg) + { + +======= + public MainWindow() + { + InitializeComponent(); +>>>>>>> 添加项目文件。 +======= +======= + LoginWindow Login = new(); +>>>>>>> 添加登录ui以及部分交互逻辑 + static string? receive; + public static int user_id = 0; + public static string? LoginMsg = "123"; + private static readonly ILog log = LogManager.GetLogger(typeof(MainWindow)); + public static Socket? Client; + public MainWindow() + { + InitializeComponent(); + log.Info("Hello World!"); + this.Hide(); + Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + try + { + log.Info("连接服务器 127.0.0.1:5555 "); + Client.Connect("127.0.0.1", 5555); + } + catch (Exception ex) + { + Client.Close(); + log.Error(ex); + } + Login.Show(); + Thread th = new Thread(Receive); + th.Start(); +>>>>>>> 添加基础功能 + } + static void Receive() + { + byte[] buffer = new byte[1024]; + try + { + while (true) + { + int num = Client!.Receive(buffer); + if (num == 0) break; + if (Client.Poll(100, SelectMode.SelectRead) && Client.Available == 0 || !Client.Connected) + { + log.Error("连接已断开"); + break; + } + receive = Encoding.UTF8.GetString(buffer, 0, num); + response(receive); + } + } + catch (Exception ex) { + log.Error(ex); + } + finally + { + Client?.Close(); + } + } + static void response(string msg) + { + LoginData data = JsonSerializer.Deserialize(msg)!; + + if (data.success) { + + } + else { + //LoginWindow.Instance.LoginMsg.Text = msg; + + } + + } + } +} \ No newline at end of file diff --git a/chatclient/chatapi.cs b/chatclient/chatapi.cs new file mode 100644 index 0000000..58f6d4a --- /dev/null +++ b/chatclient/chatapi.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace chatapi +{ + internal class LoginData + { + public bool success { get; set; } + public string? message { get; set; } + public string? token { get; set; } + public int? user_id { get; set; } + public string? username { get; set; } + } + internal class RegisterData + { + public bool success { get; set; } + public string? message { get; set; } + } +} diff --git a/chatclient/chatclient.csproj b/chatclient/chatclient.csproj new file mode 100644 index 0000000..c546d44 --- /dev/null +++ b/chatclient/chatclient.csproj @@ -0,0 +1,28 @@ + + + + WinExe + net8.0-windows + enable + enable + true + + + + + + + + + + + + + + + + PreserveNewest + + + + diff --git a/chatclient/chatclient.csproj.user b/chatclient/chatclient.csproj.user new file mode 100644 index 0000000..637a7c0 --- /dev/null +++ b/chatclient/chatclient.csproj.user @@ -0,0 +1,9 @@ + + + + + + Code + + + \ No newline at end of file diff --git a/chatclient/config/log4net.config b/chatclient/config/log4net.config new file mode 100644 index 0000000..f30cfcc --- /dev/null +++ b/chatclient/config/log4net.config @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/chatclient/user.png b/chatclient/user.png new file mode 100644 index 0000000..0ece63d Binary files /dev/null and b/chatclient/user.png differ