生命中每一件事情的发生,都有它背后的美意,如果我们能早日获知生命的密码,了悟生命的轨迹,就能在每一个阶段把握机会,创造生命的奇迹。 一、生命数的计算方法: 把出生年月的所有数字全部加起来,一直加到个位数为止。 如:1966年7月30日出生 1966 07 30 就是1+9+6+6+7+3=32 3+2=5 1968年11月7日出生 1968 11 07 计算1+9+6+8+1+1+7=33 3+3=6 生命数字密码的意义: 1、一生二,二生三,三生万物,1代表原创,新生,从我开始,代表男性、阳性的能量,自我先锋,领袖,为了找到自我,证明我的存在。需要解决自信,自我的问题。 2、2是双,代表女性、柔性的能量,为了发挥合作的力量,顺应、接纳、协调的力量。需要解决打开心门,接纳世界。 3、3是喜悦的数,开心、信任、创意、表达、新鲜,集万千宠爱于一生,需要解决情绪的问题,阳光之美。 4、4是实相,自然存在、安全、稳定、朴素、实干,通过工作来获得安全感,需要解决安全的问题,不懒惰。 5、5是充满活力,喜欢自由,敢于冒险,欲望强烈,喜欢享受、吃、玩、旅游,善于营销,做生意,需要解决危险和恐惧,冷美之人。 6、6是代表爱心,善良,关怀,服务,责任,家庭,发自内心,付出,心很敏感、细腻,需要解决从新出发,放下企求回报的心,精致之美。 7、7是代表智慧、探究、分析、理性、冷漠、单独、质疑、细致、真相,提高人道的觉知,需要解决思维问题,钻牛角尖,应该允许以不同的方式存在。 8、8是代表钱、权、力量、掌控、整合组织,追求地位,眼光远,规划大,从无到有,终生事业,心想事成,需要解决小事情翻船,要真实的面对自己。 9、9是代表付出、大爱、人道、服务,需要解决把小事情做到极致,不要迷失自己。 二、高峰挑战:36周岁减去生命数,9年为一个高峰数 如:36-5=31周岁 1、第一高峰数:36-5=31 周岁 高峰数:月+日 =高峰数 7+3=10=1 挑战数:月-日 =挑战数 7-3=4 2、第二高峰数:32—40周岁 高峰数:年+日 =高峰数 1966+30=25=7 挑战数:年-日 =挑战数 1966-30=22- 3=19=10=1 3、第三高峰数:41—49周岁 高峰数:第一高峰数+第二高峰数=1+7=8 挑战数:第一挑战数-第二挑战数=4-1=3 4、第四高峰数;50—58周岁 高峰数:年+月 =1966+07=29=11=2 挑战数:年-月 =1966-07=22-7=15=6 第一高峰数代表受父母制约的时期,第一、第二,第三、第四交界处有大事情发生,决定今后做什么? 高峰数的意义 1、捧着,众人围着你转 2、听话 3、能说会道 4、求稳,不愿面对现实 5、追求自由,别人不要管我 6、乖,本分 7、天才儿童,人际差 8、家庭条件差 9、敏感,喜欢落泪 三、个人年份 第一高峰数+流年=1+2010=4 第一高峰数+月份=1+1=2 第一高峰数+日 =1=10=2 […]
View Details我们在使用C# TextBox进行开发操作的时候经常会碰到C# TextBox的使用,那么C# TextBox的使用有没有一些常用的技巧呢?如C# TextBox换行的处理,其实就是一些常用的操作,那么这里就向你介绍几个我们常见的需求以及解决方法。 一、关于C# TextBox全选的判断: int SelectLength=this.textBox1.SelectionLength;//获取选中的字符长度 if (SelectLength == this.textBox1.Text.Length) {//判断是否全部选中 MessageBox.Show("你已经选中"); } 二、关于C# TextBox换行、设置光标位置、随文本滚动 ◆C# TextBox换行 TextBoxControl.Text += Environment.NewLine; 如何在多行TextBox中写入文本时实现换行?由于Windows系统中,回车符需两上字符。因此方法是使用\r\n标记,如 Label="Calculation " ":…….SUM\r\n"; textBox.AppendText(Label); 另外更有一个办法是用Environment.Newline的方法,能够兼容Windows和Linux系统。 ◆C# TextBox设置光标位置到文本最后 TextBoxControl.SelectionStart = TextBoxControl.TextLength; ◆C# TextBox随文本滚动 TextBoxControl.ScrollToCaret(); 如何在多行TextBox中用滚动条,使添加文本后自动滚动显示到最后一行?方法是使用ScrollToCaret方法,自动滚动到插入符的位置,如: textBox.AppendText(Label); textBox.ScrollToCaret(); 那么对于C# TextBox常用操作的内容就向你介绍到这里,希望对你了解和学习C# TextBox的使用有所帮助。 转自:http://blog.sina.com.cn/s/blog_43eb83b90100l18v.html
View Details一、确保你安装的是最新的补丁 如果门是敞开的话,在窗户上加锁就毫无意义。同样道理,如果你没有打补丁,继续下面的操作就没有什么必要。 二、隐藏Apache的版本号及其它敏感信息 默认情况下,很多Apache安装时会显示版本号及操作系统版本,甚至会显示服务器上安装的是什么样的Apache模块。这些信息可以为黑客所用,并且黑客还可以从中得知你所配置的服务器上的很多设置都是默认状态。 这里有两条语句,你需要添加到你的httpd.conf文件中: ServerSignature Off ServerTokens Prod ServerSignature出现在Apache所产生的像404页面、目录列表等页面的底部。ServerTokens目录被用来判断Apache会在Server HTTP响应包的头部填充什么信息。如果把ServerTokens设为Prod,那么HTTP响应包头就会被设置成: Server:Apache 如果你非常想尝试其它事物,你可以通过编辑源代码改成不是Apache的其它东西,或者你可以通过下面将要介绍的mod_security实现。 三、确保Apache以其自身的用户账号和组运行 有的Apache安装过程使得服务器以nobody的用户运行,所以,假定Apache和你的邮件服务器都是以nobody的账号运行的,那么通过Apache发起的攻击就可能同时攻击到邮件服务器,反之亦然。 User apache Group apache 四、确保web根目录之外的文件没有提供服务 我们不让Apache访问web根目录之外的任何文件。假设你的所以web站点文件都放在一个目录下(例如/web),你可以如下设置: Order Deny,Allow Deny from all Options None AllowOverride None Order Allow,Deny Allow from all 注意,因为我们设置Opitins None 和AllowOverride None,这将关闭服务器的所有Option和Override。你现在必须明确把每个目录设置成Option或者Override。 五、关闭目录浏览 你可以在Directory标签内用Option命令来实现这个功能。设置Option为None或者-Indexes。 Options -Indexes 六、关闭includes 这也可以通过在Directory标签内使用Option命令来实现。设置Option为None或者-Includes。 Options -Includes 七、关闭CGI执行程序 如果你不用CGI,那么请把它关闭。在目录标签中把选项设置成None或-ExecCGI就可以: Options -ExecCGI 八、禁止Apache遵循符号链接 同上,把选项设置成None或-FollowSymLinks: Options -FollowSymLinks 九、关闭多重选项 如果想关闭所有选项,很简单: Options None 如果只想关系一些独立的选项,则通过将Options做如下设置可实现: Options -ExecCGI -FollowSymLinks -Indexes 十、关闭对.htaccess文件的支持 在一个目录标签中实现: AllowOverride None 如果需要重载,则保证这些文件不能够被下载,或者把文件名改成非.htaccess文件。比如,我们可以改成.httpdoverride文件,然后像下面这样阻止所有以.ht打头的文件: AccessFileName .httpdoverride Order allow,deny Deny from all Satisfy All 十一、运行mod_security Run mod_security是O’Reilly出版社出版的Apache Security一书的作者,Ivan Ristic所写的一个非常好用的一个Apache模块。可以用它实现以下功能: ·简单过滤 ·基于过滤的常规表达式 ·URL编码验证 ·Unicode编码验证 ·审计 […]
View DetailsFCKeditor 很强大也很讨人喜欢,唯一的缺点就是不支持文件和文件夹的删除,很是遗憾。这篇文章就介绍怎样为 FCKeditor 增加删除功能(基于 C# 的版本)。 FCKeditor 官方网站:http://www.fckeditor.net本文所针对版本:FCKeditor: 2.6.4,FCKeditor.Net: 2.6.3。 1. 用 Visual Studio 2005/2008 打开项目 FCKeditor.Net 2.6.3,打开文件“FileBrowser/Connector.cs”,为 class Connector 增加如下两个成员函数:
1 |
private void DelFile( XmlNode connectorNode, string resourceType, string currentFolder ) { HttpContext hc = HttpContext.Current; string file = hc.Server.MapPath(hc.Request["FileUrl"]); if (System.IO.File.Exists(file)) System.IO.File.Delete(file); else hc.Response.Write(@"<error number=""1"" originaldescription=""unable to locate file"">"); } private void DelFolder( XmlNode connectorNode, string resourceType, string currentFolder ) { HttpContext hc = HttpContext.Current; string folder = hc.Server.MapPath(hc.Request["FolderName"]); if (System.IO.Directory.Exists(folder)) System.IO.Directory.Delete(folder, true); else hc.Response.Write(@"<error number=""2"" originaldescription=""unable to locate folder"">"); } |
2. 在文件“Connector.cs”中找到 OnLoad 函数,在 switch 部分增加以下红色代码:
1 |
// Execute the required command. switch( sCommand ) { case "GetFolders" : this.GetFolders( oConnectorNode, sResourceType, sCurrentFolder ); break; case "GetFoldersAndFiles" : this.GetFolders( oConnectorNode, sResourceType, sCurrentFolder ); this.GetFiles( oConnectorNode, sResourceType, sCurrentFolder ); break; case "CreateFolder": this.CreateFolder(oConnectorNode, sResourceType, sCurrentFolder); break; <span><font color="#ff0000" face="Courier New">case "DelFile": this.DelFile(oConnectorNode, sResourceType, sCurrentFolder); break; case "DelFolder": this.DelFolder(oConnectorNode, sResourceType, sCurrentFolder); break;</font></span> } |
3. 编译 FCKeditor.net 并关闭该项目。将生成的 FredCK.FCKeditorV2.dll 拷贝出来以备后用。 4. 建立 C# 测试项目,并在其中部署 FCKeditor 2.6.4(使用第 3 步生成的 FredCK.FCKeditorV2.dll)。精简及部署的详细步骤非本文重点,不再重复。 5. 打开“fckeditor/editor/filemanager/browser/default/frmresourceslist.htm”,修改以下两个函数
1 |
oListManager.GetFolderRowHtml = function( folderName, folderPath<font face="Courier New"><span><font color="#ff0000">, folderUrl</font></span> ) { // Build the link to view the folder. var sLink = '<a href="#" onclick="OpenFolder(\'' + ProtectPath(folderPath) + '\');return false;">'; return '<tr>' + '<td width="16">' + sLink + '<img alt="" src="images/Folder.gif" width="16" height="16" border="0"><\/a>' + '<\/td><td nowrap colspan="2"> ' + sLink + folderName + '<\/a>' + '<\/td><span><font color="#ff0000"><td align="right"><a href="#" onclick="DelFolder(\''+folderName+'\',\''+ ProtectPath(folderUrl) + '\');return false;">删除</a></td<span><font color="#ff0000">></font></span><</font></span>\/tr>'; } oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize ) { // Build the link to view the folder. var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath(fileUrl) + '\');return false;">' ; // Get the file icon. va sIcon = oIcons.GetIcon( fileName ) <span><font color="#ff0000"><td align="right"><a href="#" onclick="DelFile(\''+fileName+'\',\'' + ProtectPath(fileUrl) + '\');return false;">删除</a></td></font></span></font><\/tr>'; } |
6. 继续修改文件“frmresourceslist.htm”,在 OpenFile 函数后面增加以下两个函数:
1 |
function DelFile( fileName, fileUrl ) { if (confirm('您确定要删除文件“' + fileName + '”吗?')) oConnector.SendCommand("DelFile", "FileUrl=" + escape(fileUrl), Refresh); } function DelFolder( folderName, folderPath ) { if (confirm('您确定要删除文件夹“' + folderName + '”和里面的所有文件吗?')) oConnector.SendCommand("DelFolder", "FolderName=" + escape(folderPath + folderName), Refresh); } |
7. 继续修改文件“frmresourceslist.htm”,找到 GetFoldersAndFilesCallBack 函数中的下面这行,增加红色部分的代码:
1 |
oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/"<span><font color="#ff0000" face="Courier New">, <span><font color="#ff0000" face="Courier New"><span><font color="#ff0000" face="Courier New"><span><font color="#ff0000" face="Courier New"><span><font color="#ff0000" face="Courier New"><span><font color="#ff0000" face="Courier New"><span><font color="#ff0000" face="Courier New"><span><font color="#ff0000" face="Courier New"><span><font color="#ff0000" face="Courier New">sCurrentFolderUrl</font></span> </font></span></font></span></font></span></font></span></font></span></font></span></font></span></font></span>) ); |
至此,删除功能增加完毕,见下图: 转自:http://blog.sina.com.cn/s/blog_4dfeeb6f0100ed5j.html
View Details1.五行生克 五行相生: 金生水, 水生木, 木生火, 火生土, 土生金. 五行相克: 金克木, 木克土, 土克水, 水克火, 火克金. 2. 天干地支 十天干: 甲, 乙, 丙, 丁, 戊, 己, 庚, 辛, 壬, 癸. 十二地支: 子, 丑, 寅, 卯, 辰, 巳, 午, 未, 申, 酉, 戌, 亥. 3. 干支阴阳: 甲乙同属木, 甲为阳, 乙为阴 丙丁同属火, 丙为阳, 丁为阴 戊己同属土, 戊为阳, 己为阴 庚辛同属金, 庚为阳, 辛为阴 壬癸同属水, 壬为阳, 癸为阴 亥子同属水, 子为阳, 亥为阴 寅卯同属木, 寅为阳, 卯为阴 巳午同属火, 午为阳, 巳为阴 申酉同属金, 申为阳, 酉为阴 戌未同属土, 子为阳, 未为阴 辰丑同属土, 辰为阳, 丑为阴 干支方位: 甲乙东方木 丙丁南方火 戊己中央土 庚辛西方金 壬癸北方水 亥子北方水 寅卯东方木 巳午南方火 申酉西方金 辰戌丑未四季土 4.天干地支作用关系 4.1 天干化合: 己合化土, 乙庚合化金, 丙辛合化水, 丁壬合化木, 戊癸合化火. 4.2 地支会合冲刑: […]
View Details由于项目中编写文档结构、编写CSS的人员较多,并与程序员协同工作,就需要统一class与id的名称,前天花了一点时间,按照大多人的习惯,制定了下面的常用关键字: 容 器:container/box 头 部:header 主 导 航:mainNav 子 导 航:subNav 顶 导 航:topNav 网站标志:logo 大 广 告:banner 页面中部:mainBody 底 部:footer 菜 单:menu 菜单内容:menuContent 子 菜 单:subMenu 子菜单内容:subMenuContent 搜 索:search 搜索关键字:keyword 搜索范围:range 标签文字:tagTitle 标签内容:tagContent 当前标签:tagCurrent/currentTag 标 题:title 内 容:content 列 表:list 当前位置:currentPath 侧 边 栏:sidebar 图 标:icon 注 释:note 登 录:login 注 册:register 列 定 义:column_1of3 (三列中的第一列) column_2of3 (三列中的第二列) column_3of3 (三列中的第三列) 转自:http://www.lanrentuku.com/lanren/superlazy/20070526/superlazy182717.html
View Details1.样式命名外 套: wrap主导航: mainnav子导航: subnav页 脚: footer整个页面: content页 眉: header页 脚: footer商 标: label标 题: title主导航: mainbav(globalnav)顶导航: topnav边导航: sidebar左导航: leftsidebar右导航: rightsidebar旗 志: logo标 语: banner菜单内容1: menu1 content菜单容量: menu container子菜单: submenu边导航图标:sidebarIcon注释: note面包屑: breadcrumb(即页面所处位置导航提示)容器: container内容: content搜索: search登陆: Login功能区: shop(如购物车,收银台)当前的 current 2.另外在编辑样式表时可用的注释可这样写:<-- Footer -->内容区<-- End Footer --> 3.样式文件命名主要的 master.css布局,版面 layout.css专栏 columns.css文字 font.css打印样式 print.css主题 themes.css http://www.lanrentuku.com/lanren/superlazy/20070419/000757.html
View Details门户网站 portals website 网站导航 site map 公司简介 profile / company profile / company 公司设备 equipment 公司荣誉 glories 企业文化 culture 产品展示 product 资质认证 quality certification 企业规模 scale 营销网络 sales network 组织机构 organization 合作加盟 join in cooperation 技术力量 technology 经理致辞 managers oration 发展历程 development history 工程案例 engineering projects 业务范围 business scope 分支机构 branches 供求信息 supply & demand 经营理念 operation principle 产品销售 sales 联系我们 contact us 信息发布 information 返回首页 homepage 产品定购 order 分类浏览 browse by category 电子商务 e-business 公司实力 strength 版权所有 copy right 友情连结 hot link 应用领域 application fields 人力资源 human […]
View Details大家好,这是我最近写了一个Udp通信的小程序,发表出来和大家共同学习,我希望和大家共同进步。 upd通信接受端:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
using System; using System.Net; using System.Net.Sockets; namespace Zhty.Socket.UDPSocket { public class UDP_Client { #region 属性 private IPAddress _ClientAddress = IPAddress.Any; private int _ClientPort = 0; private byte[] _data = new byte[] { }; public IPEndPoint Client { get { return new IPEndPoint(_ClientAddress, _ClientPort); } set { _ClientAddress = value.Address; _ClientPort = value.Port; } } public IPAddress ClientAddress { get { return _ClientAddress; } set { _ClientAddress = value; } } public int ClientPort { get { return _ClientPort; } set { _ClientPort = value; } } #endregion #region 方法 public void SendMessage(byte[] message) { // Encode message per settings // Send the message _data = message; try { SendUDPMessage(_data); } catch (Exception ex) { throw ex; } } private int SendUDPMessage(Byte[] _data) { //' Create a UDP Server and send the message, then clean up UdpClient _UDPServer = null; int ReturnCode; try { _UDPServer = new UdpClient(); ReturnCode = 0; _UDPServer.Connect(Client); ReturnCode = _UDPServer.Send(_data, _data.Length); } catch (Exception ex) { throw ex; } finally { if (_UDPServer != null) { _UDPServer.Close(); } } return ReturnCode; } #endregion } } |
udp通信的发送端:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.Net.Sockets; using System.Net; namespace Zhty.Socket.UDPSocket { public class UDP_Server { private Thread _ThreadReceive; private int _ClientPort = 0; private string _Message = null; private UdpClient _UDPClient; private IPEndPoint _Server = new IPEndPoint(IPAddress.Any, 0); private int _BytesReceived = 0; #region 事件定义 public delegate void OnReceivedDataHandler(object sender, DataReceivedEventArgs e); public event OnReceivedDataHandler OnRecivedData; public delegate void OnStateChangedHandler(object sender, ServerStateChangeEventArgs e); public event OnStateChangedHandler OnStateChanged; #endregion #region 属性 int _bufferSize = 1024; public int BufferSize { get { return _bufferSize; } set { _bufferSize = value; } } public int BytesReceived { get { return _BytesReceived; } } public string Message { get { return _Message; } } public int ClientPort { get { return _ClientPort; } set { _ClientPort = value; } } #endregion #region 方法 void DataReceiveProc() { //BeforeReceive(this,new EventArgs()); _Message = ""; byte[] data = new byte[BufferSize]; try { data = _UDPClient.Receive(ref _Server); if (OnRecivedData != null) OnRecivedData(this, new DataReceivedEventArgs(data)); Thread.Sleep(100); } catch (Exception ex) { if (OnStateChanged != null) OnStateChanged(this, new ServerStateChangeEventArgs(false)); throw ex; } finally { InitializeThread(); } } private void InitializeClient() { if (_UDPClient == null) { this._UDPClient = new UdpClient(ClientPort); } } private void InitializeThread() { try { _ThreadReceive = new Thread(new ThreadStart(DataReceiveProc)); _ThreadReceive.Start(); } catch (Exception ex) { throw ex; } } public void Start() { InitializeClient(); InitializeThread(); } #endregion public void Stop() { try { _ThreadReceive.Abort(); if (_UDPClient != null) { // ' Close the UDPClient and then force it to Nothing _UDPClient.Close(); _UDPClient = null; } } catch (Exception ex) { throw ex; } } #region 析构方法 ~UDP_Server() { Stop(); } #endregion } } |
辅助类:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
using System; using System.Collections.Generic; using System.Text; namespace Zhty.Socket.UDPSocket { public class DataReceivedEventArgs : EventArgs { public DataReceivedEventArgs(byte[] data) { Data = data; } byte[] m_Data; public byte[] Data { get { return m_Data; } set { m_Data = value; } } } public class ServerStateChangeEventArgs : EventArgs { public ServerStateChangeEventArgs(bool state) { Running = state; } bool m_Running; public bool Running { get { return m_Running; } set { m_Running = value; } } } } |
转自:http://www.cnblogs.com/zhaotianyu001/articles/549259.html
View DetailsInternet协议族中有支持无连接的传输协议,即UDP协议。UDP协议提供了一种方法来发送经过封装的IP数据报,而且不必建立连接就 可以发送这些IP数据报。 服务器端:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Net.Sockets; namespace UDPServer { class Program { static void Main(string[] args) { int recv; byte[] data = new byte[1024]; //构建TCP 服务器 //得到本机IP,设置TCP端口号 IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 8001); Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //绑定网络地址 newsock.Bind(ipep); Console.WriteLine("This is a Server, host name is {0}", Dns.GetHostName()); //等待客户机连接 Console.WriteLine("Waiting for a client"); //得到客户机IP IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); EndPoint Remote = (EndPoint)(sender); recv = newsock.ReceiveFrom(data, ref Remote); Console.WriteLine("Message received from {0}: ", Remote.ToString()); Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv)); //客户机连接成功后,发送欢迎信息 string welcome = "Welcome ! "; //字符串与字节数组相互转换 data = Encoding.ASCII.GetBytes(welcome); //发送信息 newsock.SendTo(data, data.Length, SocketFlags.None, Remote); while (true) { data = new byte[1024]; //发送接受信息 recv = newsock.ReceiveFrom(data, ref Remote); Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv)); newsock.SendTo(data, recv, SocketFlags.None, Remote); } } } } |
客户端:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; namespace UDPClient { class Program { static void Main(string[] args) { byte[] data = new byte[1024]; string input, stringData; //构建TCP 服务器 Console.WriteLine("This is a Client, host name is {0}", Dns.GetHostName()); //设置服务IP,设置TCP端口号 IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8001); //定义网络类型,数据连接类型和网络协议UDP Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); string welcome = "Hello! "; data = Encoding.ASCII.GetBytes(welcome); server.SendTo(data, data.Length, SocketFlags.None, ipep); IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); EndPoint Remote = (EndPoint)sender; data = new byte[1024]; //对于不存在的IP地址,加入此行代码后,可以在指定时间内解除阻塞模式限制 //server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 100); int recv = server.ReceiveFrom(data, ref Remote); Console.WriteLine("Message received from {0}: ", Remote.ToString()); Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv)); while (true) { input = Console.ReadLine(); if (input == "exit") break; server.SendTo(Encoding.ASCII.GetBytes(input), Remote); data = new byte[1024]; recv = server.ReceiveFrom(data, ref Remote); stringData = Encoding.ASCII.GetString(data, 0, recv); Console.WriteLine(stringData); } Console.WriteLine("Stopping Client."); server.Close(); } } } |
MSDN 实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
// This constructor arbitrarily assigns the local port number. UdpClient udpClient = new UdpClient(11000); try{ udpClient.Connect("www.contoso.com ", 11000); // Sends a message to the host to which you have connected. Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there?"); udpClient.Send(sendBytes, sendBytes.Length); // Sends a message to a different host using optional hostname and port parameters. UdpClient udpClientB = new UdpClient(); udpClientB.Send(sendBytes, sendBytes.Length, "AlternateHostMachineName", 11000); //IPEndPoint object will allow us to read datagrams sent from any source. IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); // Blocks until a message returns on this socket from a remote host. Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); string returnData = Encoding.ASCII.GetString(receiveBytes); // Uses the IPEndPoint object to determine which of these two hosts responded. Console.WriteLine("This is the message you received " + returnData.ToString()); Console.WriteLine("This message was sent from " + RemoteIpEndPoint.Address.ToString() + " on their port number " + RemoteIpEndPoint.Port.ToString()); udpClient.Close(); udpClientB.Close(); } catch (Exception e ) { Console.WriteLine(e.ToString()); } |
Microsoft Visual Studio 2005/.NET Framework 2.0 同时提供下列产品的其他版本: •.NET Framework 3.0 •Microsoft Visual Studio 2008/.NET Framework 3.5 .NET Framework 类库UdpClient 成员 提供用户数据报 (UDP) 网络服务。 下表列出了由 UdpClient 类型公开的成员。 公共构造函数 名称 说明 UdpClient 已重载。初始化 UdpClient 类的新实例。 公共属性 (请参见 受保护的属性 ) 名称 说明 Available 获取从网络接收的可读取的数据量。 Client 获取或设置基础网络 Socket。 DontFragment 获取或设置 Boolean 值,指定 UdpClient 是否允许对 Internet 协议 (IP) 数据报进行分段。 EnableBroadcast 获取或设置 Boolean 值,指定 UdpClient 是否可以发送或接收广播数据包。 ExclusiveAddressUse 获取或设置 Boolean 值,指定 UdpClient 是否只允许一个客户端使用端口。 MulticastLoopback 获取或设置 Boolean 值,指定是否将输出多路广播数据包传递给发送应用程序。 Ttl 获取或设置一个值,指定由 UdpClient 发送的 Internet […]
View Details