mirror of
https://e.coding.net/circlecloud/SixiBroadcast.git
synced 2025-11-24 23:56:05 +00:00
服务器修改为控制台界面 客户端完全隐藏界面...
This commit is contained in:
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,9 +60,15 @@ namespace UDPServer
|
||||
int port = int.Parse(info[2]);
|
||||
IPEndPoint addr = new IPEndPoint(IPAddress.Parse(ip), port);
|
||||
if (userinfo.ContainsKey(user))
|
||||
userinfo.Remove(user);
|
||||
userinfo.Add(user, addr);
|
||||
Console.WriteLine("用户: " + user + " 登录服务器 IP: " + ip + " 端口: " + port);
|
||||
{
|
||||
userinfo[user] = addr;
|
||||
Console.WriteLine("用户: " + user + " 更新数据 IP: " + ip + " 端口: " + port);
|
||||
}
|
||||
else
|
||||
{
|
||||
userinfo.Add(user, addr);
|
||||
Console.WriteLine("用户: " + user + " 登录服务器 IP: " + ip + " 端口: " + port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,7 +76,6 @@ namespace UDPServer
|
||||
{
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user