mirror of
https://e.coding.net/circlecloud/SixiBroadcast.git
synced 2024-11-23 11:58:46 +00:00
服务器修改为控制台界面 客户端完全隐藏界面...
This commit is contained in:
parent
e83960ff89
commit
e3a249fe54
75
UDPClient/Frm_Client.Designer.cs
generated
75
UDPClient/Frm_Client.Designer.cs
generated
@ -30,57 +30,20 @@
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Frm_Client));
|
||||
this.portT = new System.Windows.Forms.TextBox();
|
||||
this.listen = new System.Windows.Forms.Button();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.msgbox = new System.Windows.Forms.ListBox();
|
||||
this.notifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
|
||||
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.退出ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.contextMenuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// portT
|
||||
//
|
||||
this.portT.Location = new System.Drawing.Point(71, 13);
|
||||
this.portT.Name = "portT";
|
||||
this.portT.Size = new System.Drawing.Size(161, 21);
|
||||
this.portT.TabIndex = 0;
|
||||
this.portT.Text = "25333";
|
||||
//
|
||||
// listen
|
||||
//
|
||||
this.listen.Location = new System.Drawing.Point(238, 11);
|
||||
this.listen.Name = "listen";
|
||||
this.listen.Size = new System.Drawing.Size(42, 23);
|
||||
this.listen.TabIndex = 2;
|
||||
this.listen.Text = "监听";
|
||||
this.listen.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(12, 16);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(53, 12);
|
||||
this.label2.TabIndex = 6;
|
||||
this.label2.Text = "广播端口";
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(196, 40);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(84, 23);
|
||||
this.button2.TabIndex = 8;
|
||||
this.button2.Text = "闪烁测试";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||
//
|
||||
// msgbox
|
||||
//
|
||||
this.msgbox.FormattingEnabled = true;
|
||||
this.msgbox.ItemHeight = 12;
|
||||
this.msgbox.Location = new System.Drawing.Point(14, 79);
|
||||
this.msgbox.Location = new System.Drawing.Point(14, 7);
|
||||
this.msgbox.Name = "msgbox";
|
||||
this.msgbox.Size = new System.Drawing.Size(266, 184);
|
||||
this.msgbox.Size = new System.Drawing.Size(266, 256);
|
||||
this.msgbox.TabIndex = 10;
|
||||
//
|
||||
// notifyIcon
|
||||
@ -90,33 +53,43 @@
|
||||
this.notifyIcon.Visible = true;
|
||||
this.notifyIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon_MouseDoubleClick);
|
||||
//
|
||||
// contextMenuStrip1
|
||||
//
|
||||
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.退出ToolStripMenuItem});
|
||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(153, 48);
|
||||
//
|
||||
// 退出ToolStripMenuItem
|
||||
//
|
||||
this.退出ToolStripMenuItem.Name = "退出ToolStripMenuItem";
|
||||
this.退出ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.退出ToolStripMenuItem.Text = "退出";
|
||||
this.退出ToolStripMenuItem.Click += new System.EventHandler(this.退出ToolStripMenuItem_Click);
|
||||
//
|
||||
// Frm_Client
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(292, 273);
|
||||
this.Controls.Add(this.msgbox);
|
||||
this.Controls.Add(this.button2);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.listen);
|
||||
this.Controls.Add(this.portT);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.Name = "Frm_Client";
|
||||
this.ShowInTaskbar = false;
|
||||
this.Text = "客户端";
|
||||
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
|
||||
this.Load += new System.EventHandler(this.Frm_Client_Load);
|
||||
this.contextMenuStrip1.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TextBox portT;
|
||||
private System.Windows.Forms.Button listen;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.ListBox msgbox;
|
||||
private System.Windows.Forms.NotifyIcon notifyIcon;
|
||||
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
|
||||
private System.Windows.Forms.ToolStripMenuItem 退出ToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,17 +9,18 @@ using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using UDPClient.Properties;
|
||||
|
||||
namespace UDPClient
|
||||
{
|
||||
public partial class Frm_Client : Form
|
||||
{
|
||||
Icon ico1 = new Icon("icon.ico");
|
||||
Icon ico2 = new Icon("clear.ico");
|
||||
bool is1;
|
||||
Icon icoOn = Resources.IconOn;
|
||||
Icon icoOff = Resources.IconOff;
|
||||
bool isOn;
|
||||
bool isTwinkle;
|
||||
static UdpClient client;
|
||||
static IPEndPoint endpoint;
|
||||
static IPEndPoint serverendpoint;
|
||||
static System.Windows.Forms.Timer tmr = new System.Windows.Forms.Timer();
|
||||
|
||||
public Frm_Client()
|
||||
@ -30,7 +31,7 @@ namespace UDPClient
|
||||
private void Frm_Client_Load(object sender, EventArgs e)
|
||||
{
|
||||
client = new UdpClient(new IPEndPoint(IPAddress.Any, 25333));
|
||||
endpoint = new IPEndPoint(IPAddress.Any, 0);
|
||||
serverendpoint = new IPEndPoint(IPAddress.Loopback, 25433);
|
||||
//启动客户端监听
|
||||
Thread t = new Thread(new ThreadStart(ClientThread));
|
||||
t.IsBackground = true;
|
||||
@ -43,20 +44,22 @@ namespace UDPClient
|
||||
tmr.Interval = 390;
|
||||
tmr.Tick += tmr_Tick;
|
||||
tmr.Enabled = true;
|
||||
|
||||
notifyIcon.ShowBalloonTip(1000, "四喜消息提示", "欢迎使用四喜消息提示系统!", ToolTipIcon.Info);
|
||||
}
|
||||
|
||||
void tmr_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (!isTwinkle) return;
|
||||
if (is1)
|
||||
if (isOn)
|
||||
{
|
||||
is1 = false;
|
||||
notifyIcon.Icon = ico2;
|
||||
isOn = false;
|
||||
notifyIcon.Icon = icoOff;
|
||||
}
|
||||
else
|
||||
{
|
||||
is1 = true;
|
||||
notifyIcon.Icon = ico1;
|
||||
isOn = true;
|
||||
notifyIcon.Icon = icoOn;
|
||||
}
|
||||
}
|
||||
public static IPAddress GetHostIP()
|
||||
@ -73,7 +76,7 @@ namespace UDPClient
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void WebListen()
|
||||
private void WebListen()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -81,7 +84,7 @@ namespace UDPClient
|
||||
listerner.AuthenticationSchemes = AuthenticationSchemes.Anonymous;//指定身份验证 Anonymous匿名访问
|
||||
listerner.Prefixes.Add("http://127.0.0.1:2533/web/");
|
||||
listerner.Start();
|
||||
Console.WriteLine("WebServer Start Successed.......");
|
||||
Console.WriteLine("网页服务器开始监听.......");
|
||||
while (true)
|
||||
{
|
||||
//等待请求连接
|
||||
@ -94,16 +97,16 @@ namespace UDPClient
|
||||
IPAddress addr = GetHostIP();
|
||||
string str = username + " " + (addr == null ? "null" : addr.ToString()) + " 25333";
|
||||
Console.WriteLine(str);
|
||||
byte[] buf = Encoding.Default.GetBytes(str);
|
||||
client.Send(buf, buf.Length, new IPEndPoint(IPAddress.Parse("127.0.0.1"), 25433));
|
||||
|
||||
byte[] buf = Encoding.UTF8.GetBytes(str);
|
||||
client.Send(buf, buf.Length, serverendpoint);
|
||||
notifyIcon.ShowBalloonTip(1000, "四喜消息提示", "用户登录成功!", ToolTipIcon.Info);
|
||||
}
|
||||
ctx.Response.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("网页服务器出现错误: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,30 +117,29 @@ namespace UDPClient
|
||||
Console.WriteLine("客户端开始监听...");
|
||||
while (true)
|
||||
{
|
||||
byte[] buf = client.Receive(ref endpoint);
|
||||
string msg = Encoding.Default.GetString(buf);
|
||||
Console.WriteLine("收到数据: " + msg);
|
||||
byte[] buf = client.Receive(ref serverendpoint);
|
||||
string msg = Encoding.UTF8.GetString(buf);
|
||||
isTwinkle = true;
|
||||
notifyIcon.ShowBalloonTip(1000,"四喜消息提示","您有新的提醒 请注意查收!",ToolTipIcon.Info);
|
||||
notifyIcon.ShowBalloonTip(1000, "四喜消息提示", msg, ToolTipIcon.Info);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("UDP客户端出现错误: " + e.Message);
|
||||
client.Close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
isTwinkle = !isTwinkle;
|
||||
}
|
||||
|
||||
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
isTwinkle = false;
|
||||
notifyIcon.Icon = ico1;
|
||||
notifyIcon.Icon = icoOn;
|
||||
}
|
||||
|
||||
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -422,6 +422,9 @@
|
||||
AAAAAwAA////AAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAA=
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>130, 17</value>
|
||||
</metadata>
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
AAABAAQAEBAAAAEACABoBQAARgAAADAwAAABACAAqCUAAK4FAAAgIAAAAQAgAKgQAABWKwAAGBgAAAEA
|
||||
|
20
UDPClient/Properties/Resources.Designer.cs
generated
20
UDPClient/Properties/Resources.Designer.cs
generated
@ -59,5 +59,25 @@ namespace UDPClient.Properties {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似于 (Icon) 的 System.Drawing.Icon 类型的本地化资源。
|
||||
/// </summary>
|
||||
internal static System.Drawing.Icon IconOff {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("IconOff", resourceCulture);
|
||||
return ((System.Drawing.Icon)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似于 (Icon) 的 System.Drawing.Icon 类型的本地化资源。
|
||||
/// </summary>
|
||||
internal static System.Drawing.Icon IconOn {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("IconOn", resourceCulture);
|
||||
return ((System.Drawing.Icon)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
@ -60,6 +60,7 @@
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
@ -68,9 +69,10 @@
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
@ -85,9 +87,10 @@
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
@ -114,4 +117,11 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="IconOff" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\IconOff.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="IconOn" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\IconOn.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
Binary file not shown.
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Binary file not shown.
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
@ -5,12 +5,27 @@
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{69C59230-BE16-4E03-8948-664F78D85698}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>UDPClient</RootNamespace>
|
||||
<AssemblyName>UDPClient</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<PublishUrl>发布\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@ -78,12 +93,20 @@
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="clear.ico">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="icon.ico">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="Resources\IconOff.ico" />
|
||||
<None Include="Resources\IconOn.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
120
UDPServer/Frm_Server.Designer.cs
generated
120
UDPServer/Frm_Server.Designer.cs
generated
@ -1,120 +0,0 @@
|
||||
namespace UDPServer
|
||||
{
|
||||
partial class Frm_Server
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows 窗体设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.msg = new System.Windows.Forms.TextBox();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.msgbox = new System.Windows.Forms.ListBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.portT = new System.Windows.Forms.TextBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// msg
|
||||
//
|
||||
this.msg.Location = new System.Drawing.Point(71, 39);
|
||||
this.msg.Name = "msg";
|
||||
this.msg.Size = new System.Drawing.Size(161, 21);
|
||||
this.msg.TabIndex = 0;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(238, 39);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(42, 23);
|
||||
this.button1.TabIndex = 1;
|
||||
this.button1.Text = "广播";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button_Click);
|
||||
//
|
||||
// msgbox
|
||||
//
|
||||
this.msgbox.FormattingEnabled = true;
|
||||
this.msgbox.ItemHeight = 12;
|
||||
this.msgbox.Location = new System.Drawing.Point(12, 77);
|
||||
this.msgbox.Name = "msgbox";
|
||||
this.msgbox.Size = new System.Drawing.Size(268, 184);
|
||||
this.msgbox.TabIndex = 2;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(12, 42);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(53, 12);
|
||||
this.label1.TabIndex = 3;
|
||||
this.label1.Text = "消 息";
|
||||
//
|
||||
// portT
|
||||
//
|
||||
this.portT.Location = new System.Drawing.Point(71, 12);
|
||||
this.portT.Name = "portT";
|
||||
this.portT.Size = new System.Drawing.Size(161, 21);
|
||||
this.portT.TabIndex = 4;
|
||||
this.portT.Text = "25333";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(12, 15);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(53, 12);
|
||||
this.label2.TabIndex = 5;
|
||||
this.label2.Text = "广播端口";
|
||||
//
|
||||
// Frm_Server
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(292, 273);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.portT);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.msgbox);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.msg);
|
||||
this.Name = "Frm_Server";
|
||||
this.Text = "服务端";
|
||||
this.Load += new System.EventHandler(this.Frm_Server_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TextBox msg;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.ListBox msgbox;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.TextBox portT;
|
||||
private System.Windows.Forms.Label label2;
|
||||
}
|
||||
}
|
||||
|
@ -1,120 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace UDPServer
|
||||
@ -10,12 +14,9 @@ namespace UDPServer
|
||||
/// <summary>
|
||||
/// 应用程序的主入口点。
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Frm_Server());
|
||||
new ServerListen(25433);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace UDPServer
|
||||
{
|
||||
public partial class Frm_Server : Form
|
||||
class ServerListen
|
||||
{
|
||||
UdpClient client;
|
||||
IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 0);
|
||||
Dictionary<string, IPEndPoint> userinfo = new Dictionary<string, IPEndPoint>();
|
||||
public Frm_Server()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Frm_Server_Load(object sender, EventArgs e)
|
||||
public ServerListen(int port)
|
||||
{
|
||||
client = new UdpClient(new IPEndPoint(IPAddress.Any, 25433));
|
||||
client = new UdpClient(new IPEndPoint(IPAddress.Any, port));
|
||||
//启动客户端监听
|
||||
Thread t = new Thread(new ThreadStart(ClientThread));
|
||||
t.IsBackground = true;
|
||||
t.Start();
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine("请输入需要公告的内容: ");
|
||||
string msg = Console.ReadLine();
|
||||
BroadcastMsg(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMsg(string username, string msg)
|
||||
{
|
||||
Console.WriteLine("发送给用户: " + username + " 消息: " + msg);
|
||||
byte[] buf = Encoding.UTF8.GetBytes(msg);
|
||||
client.Send(buf, buf.Length, userinfo[username]);
|
||||
}
|
||||
|
||||
private void button_Click(object sender, EventArgs e)
|
||||
private void BroadcastMsg(string msg)
|
||||
{
|
||||
foreach (var item in userinfo)
|
||||
{
|
||||
byte[] buf = Encoding.Default.GetBytes("用户: " + item.Key + " 消息: " + msg.Text);
|
||||
client.Send(buf, buf.Length, item.Value);
|
||||
sendMsg(item.Key, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +51,7 @@ namespace UDPServer
|
||||
while (true)
|
||||
{
|
||||
byte[] buf = client.Receive(ref endpoint);
|
||||
string msg = Encoding.Default.GetString(buf);
|
||||
string msg = Encoding.UTF8.GetString(buf);
|
||||
string[] info = msg.Split(' ');
|
||||
if (info.Length == 3)
|
||||
{
|
||||
@ -58,17 +60,22 @@ namespace UDPServer
|
||||
int port = int.Parse(info[2]);
|
||||
IPEndPoint addr = new IPEndPoint(IPAddress.Parse(ip), port);
|
||||
if (userinfo.ContainsKey(user))
|
||||
userinfo.Remove(user);
|
||||
{
|
||||
userinfo[user] = addr;
|
||||
Console.WriteLine("用户: " + user + " 更新数据 IP: " + ip + " 端口: " + port);
|
||||
}
|
||||
else
|
||||
{
|
||||
userinfo.Add(user, addr);
|
||||
Console.WriteLine("用户: " + user + " 登录服务器 IP: " + ip + " 端口: " + port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
client.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -46,17 +46,9 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Frm_Server.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Frm_Server.Designer.cs">
|
||||
<DependentUpon>Frm_Server.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="Frm_Server.resx">
|
||||
<DependentUpon>Frm_Server.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="ServerListen.cs" />
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
|
Loading…
Reference in New Issue
Block a user