diff --git a/chatclient/MainWindow.xaml b/chatclient/MainWindow.xaml
index 144a7c0..a81236f 100644
--- a/chatclient/MainWindow.xaml
+++ b/chatclient/MainWindow.xaml
@@ -10,9 +10,6 @@
mc:Ignorable="d"
Title="ChatWindow" Height="450" Width="800" MinHeight="240" MinWidth="380"
Style="{StaticResource MaterialDesignWindow}" Closed="MainWindow_Closed" Loaded="MainWindow_Loaded">
-
-
-
diff --git a/chatserver/Program.cs b/chatserver/Program.cs
index 6ed120c..f83f425 100644
--- a/chatserver/Program.cs
+++ b/chatserver/Program.cs
@@ -9,6 +9,7 @@ using System.Text.Json;
using System.Reflection;
using static log4net.Appender.FileAppender;
using System.IO.Compression;
+using System.Text;
[assembly: XmlConfigurator(ConfigFile = "config/log4net.config", Watch = true)]
namespace chatserver
@@ -50,7 +51,7 @@ namespace chatserver
public static void OpenUser_db()
{
log.Info("正在打开数据库连接...");
- User_db = new SQLiteConnection("Data Source=ServerUser.db;Version=3;"); //没有数据库则自动创建
+ User_db = new SQLiteConnection("Data Source=ServerUser.db;Version=3;");
User_db.Open();
InitializeTable();
log.Info("数据库连接已打开");
@@ -59,6 +60,18 @@ namespace chatserver
{
const int prefixSize = sizeof(int);
byte[] prefixBuffer = new byte[prefixSize];
+ int received = socket.Receive(prefixBuffer, 0, 4, SocketFlags.Peek);
+ if (received == 4)
+ {
+ string httpStart = Encoding.ASCII.GetString(prefixBuffer);
+ if (httpStart.StartsWith("GET") || httpStart.StartsWith("POST") ||
+ httpStart.StartsWith("HEAD") || httpStart.StartsWith("HTTP"))
+ {
+ log.Warn("检测到HTTP请求,拒绝连接");
+ socket.Close();
+ return;
+ }
+ }
try
{
while (true)