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/LoginWindow.xaml b/chatclient/LoginWindow.xaml
index 0e55712..df76a3c 100644
--- a/chatclient/LoginWindow.xaml
+++ b/chatclient/LoginWindow.xaml
@@ -6,7 +6,8 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="clr-namespace:chatclient"
mc:Ignorable="d"
- Title="LoginWindow" Height="600" Width="360">
+ Title="LoginWindow" Height="590" Width="360" MinHeight="590" MinWidth="360" MaxHeight="590" MaxWidth="360"
+ ResizeMode="NoResize">
@@ -14,24 +15,29 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/chatclient/LoginWindow.xaml.cs b/chatclient/LoginWindow.xaml.cs
index 8a5f088..75c56ae 100644
--- a/chatclient/LoginWindow.xaml.cs
+++ b/chatclient/LoginWindow.xaml.cs
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
using System.Text;
+using System.Text.Json;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@@ -11,18 +13,69 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
+using System.Net.Sockets;
+using System.IO;
+using log4net;
+using log4net.Config;
+
namespace chatclient
{
///
/// LoginWindow.xaml 的交互逻辑
///
- public partial class LoginWindow : Window
+ public partial class LoginWindow : Window,INotifyPropertyChanged
{
+ private static readonly ILog log = LogManager.GetLogger(typeof(LoginWindow));
public LoginWindow()
{
InitializeComponent();
+ this.DataContext = this;
+ }
+
+ public event PropertyChangedEventHandler? PropertyChanged;
+ private void Update (string UpdateName)
+ {
+ PropertyChangedEventHandler? handler = PropertyChanged;
+ if (handler != null)
+ {
+ handler(this, new PropertyChangedEventArgs(UpdateName));
+ }
+ }
+ private string? _LoginMsg;
+ public string UserName { get; set; } = "";
+ public string UserPassword { get; set; } = "";
+ public string? LoginMsg
+ {
+ get { return _LoginMsg; }
+ set
+ {
+ _LoginMsg = value;
+ Update("LoginMsg");
+ }
+ }
+ private void Login_Click(object sender, RoutedEventArgs e)
+ {
+ if (UserName == "")
+ {
+ LoginMsg = "用户名不能为空";
+ }
+ else if (UserPassword == "")
+ {
+ LoginMsg = "密码不能为空";
+ }
+ else
+ {
+ var LoginData = new
+ {
+ type = "login",
+ username = UserName,
+ password = UserPassword
+ };
+ string LoginLsonData = JsonSerializer.Serialize(LoginData);
+ byte[] dataBytes = Encoding.UTF8.GetBytes(LoginLsonData);
+ MainWindow.Client.Send(dataBytes);
+ }
}
-
}
}
diff --git a/chatclient/MainWindow.xaml b/chatclient/MainWindow.xaml
index 268d1d2..2633770 100644
--- a/chatclient/MainWindow.xaml
+++ b/chatclient/MainWindow.xaml
@@ -6,22 +6,27 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="clr-namespace:chatclient"
mc:Ignorable="d"
- Title="ChatWindow" Height="450" Width="800"
+ Title="ChatWindow" Height="450" Width="800" MinHeight="240" MinWidth="380"
Style="{StaticResource MaterialDesignWindow}">
-
+
+
+
+
-
-
+
+
-
-
-
+
+
+
@@ -31,7 +36,7 @@
-
+
diff --git a/chatclient/MainWindow.xaml.cs b/chatclient/MainWindow.xaml.cs
index b29bc62..6ceea4f 100644
--- a/chatclient/MainWindow.xaml.cs
+++ b/chatclient/MainWindow.xaml.cs
@@ -8,6 +8,13 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using System.Net.Sockets;
+using System.Net;
+using System.IO;
+using System;
+using System.Security.Policy;
+using log4net;
+using log4net.Config;
namespace chatclient
{
@@ -16,14 +23,51 @@ namespace chatclient
///
public partial class MainWindow : Window
{
+ static string? receive;
+ 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) {
+ log.Error(ex);
+ }
+ LoginWindow Login = new LoginWindow();
+ Login.Show();
+ Thread th = new Thread(Receive);
+ th.Start();
}
-
- private void PackIcon_DpiChanged()
+ static void Receive()
{
-
+ byte[] buffer = new byte[1024];
+ try
+ {
+ while (true)
+ {
+ int num = Client.Receive(buffer);
+ if (num == 0) break;
+ receive = Encoding.UTF8.GetString(buffer, 0, num);
+ response(receive);
+ }
+ }
+ catch (Exception ex) {
+ log.Error(ex);
+ }
+ finally
+ {
+ Client.Close();
+ }
+ }
+ static void response(string msg) {
+
}
}
}
\ No newline at end of file
diff --git a/chatclient/chatapi.cs b/chatclient/chatapi.cs
new file mode 100644
index 0000000..3f2b168
--- /dev/null
+++ b/chatclient/chatapi.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace chatclient
+{
+ internal class api
+ {
+ }
+}
diff --git a/chatclient/chatclient.csproj b/chatclient/chatclient.csproj
index 25fe900..5dd3511 100644
--- a/chatclient/chatclient.csproj
+++ b/chatclient/chatclient.csproj
@@ -9,9 +9,14 @@
+
+
+
+
+
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