1
0
mirror of https://e.coding.net/circlecloud/SixiBroadcast.git synced 2024-11-23 11:58:46 +00:00

客户端添加开机自动启 服务端添加指令系统...

This commit is contained in:
j502647092 2015-08-07 14:42:39 +08:00
parent e3a249fe54
commit 11bc60af26
2 changed files with 35 additions and 3 deletions

View File

@ -9,6 +9,7 @@ using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using Microsoft.Win32;
using UDPClient.Properties; using UDPClient.Properties;
namespace UDPClient namespace UDPClient
@ -30,6 +31,12 @@ namespace UDPClient
private void Frm_Client_Load(object sender, EventArgs e) private void Frm_Client_Load(object sender, EventArgs e)
{ {
//开机自启动添加
string path = Application.ExecutablePath;
RegistryKey rk = Registry.LocalMachine.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
rk.SetValue("SixiBroadcast", path);
rk.Close();
//初始化数据
client = new UdpClient(new IPEndPoint(IPAddress.Any, 25333)); client = new UdpClient(new IPEndPoint(IPAddress.Any, 25333));
serverendpoint = new IPEndPoint(IPAddress.Loopback, 25433); serverendpoint = new IPEndPoint(IPAddress.Loopback, 25433);
//启动客户端监听 //启动客户端监听

View File

@ -20,11 +20,36 @@ namespace UDPServer
//启动客户端监听 //启动客户端监听
Thread t = new Thread(new ThreadStart(ClientThread)); Thread t = new Thread(new ThreadStart(ClientThread));
t.Start(); t.Start();
Console.WriteLine("请输入指令 或者 /help 查看帮助");
while (true) while (true)
{ {
Console.WriteLine("请输入需要公告的内容: ");
string msg = Console.ReadLine(); string msg = Console.ReadLine();
BroadcastMsg(msg); if (msg.StartsWith("/"))
{
switch (msg.Substring(1))
{
case "help":
Console.WriteLine("/list 查看在线人员");
Console.WriteLine("/broadcast 发送公告");
break;
case "list":
Console.Write("当前在线(" + userinfo.Keys.Count + "): ");
foreach (var item in userinfo)
{
Console.Write(item.Key + " ");
}
break;
case "broadcast":
if (msg.IndexOf(' ') > 0)
BroadcastMsg(msg.Substring(msg.IndexOf(' ')));
else
Console.WriteLine("请输入公告内容!");
break;
default:
Console.WriteLine("未知命令 请输入指令 或者 /help 查看帮助");
break;
}
}
} }
} }
@ -67,7 +92,7 @@ namespace UDPServer
else else
{ {
userinfo.Add(user, addr); userinfo.Add(user, addr);
Console.WriteLine("用户: " + user + " 登录服务器 IP: " + ip + " 端口: " + port); Console.WriteLine("用户: " + user + " 登录服务器 IP: " + ip + " 端口: " + port + "当前在线: " + userinfo.Keys.Count);
} }
} }
} }