登录
首页 » C# » c#FORM服务器客户端UDP通讯实例

c#FORM服务器客户端UDP通讯实例

于 2020-05-31 发布
0 194
下载积分: 1 下载次数: 1

代码说明:

服务器客户端UDP广播通话 【核心代码】using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Net.Sockets;using System.Net;namespace NetServer{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { this.Close(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { //使用UDP协议发送数据 Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //设置端口号 IPEndPoint ieps = new IPEndPoint(IPAddress.Broadcast, 8900); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1); //将发送数据转换为字节数组 byte[] bytess = System.Text.Encoding.Unicode.GetBytes(textBox1.Text); socket.SendTo(bytess, ieps); socket.Close(); } }}

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • DCOM授权
    DCOM授权
    2014-03-11下载
    积分:1
  • C# 判断当前系统是32位 还是 64位 源码
    C# 判断当前系统是32位 还是 64位 源码
    2014-01-27下载
    积分:1
  • C/C++经典面试题
    50个C、C 面试题.pdfC/C 经典面试题
    2020-06-05下载
    积分:1
  • c打字游戏代码.zip
    c语言打字游戏代码.zip
    2019-11-06下载
    积分:1
  • C# 文件信息查看器(实现了拖放文件并查看文件信息)
    可以查看 文件的版本、公司、
    2015-03-14下载
    积分:1
  • C# 制作的OFFICE2007皮肤的源码- 自定义皮肤代码
    C# 制作的OFFICE2007皮肤的源码
    2015-04-29下载
    积分:1
  • 类迅雷的悬浮窗程序
    类迅雷的悬浮窗程序
    2013-12-30下载
    积分:1
  • 扫雷游戏
    简单的扫雷游戏
    2020-12-08下载
    积分:1
  • C# 实现 MD5加密解密算法
    using System.Security.Cryptography;using    System.IO;  using    System.Text; ///MD5加密  public string MD5Encrypt(string    pToEncrypt,  string    sKey)    {       DESCryptoServiceProvider    des  =  new    DESCryptoServiceProvider();     byte[]    inputByteArray  =    Encoding.Default.GetBytes(pToEncrypt);       des.Key  =    ASCIIEncoding.ASCII.GetBytes(sKey);       des.IV  =    ASCIIEncoding.ASCII.GetBytes(sKey);       MemoryStream    ms  =  new    MemoryStream();       CryptoStream    cs  =  new    CryptoStream(ms,    des.CreateEncryptor(),CryptoStreamMode.Write);       cs.Write(inputByteArray,  0,    inputByteArray.Length);       cs.FlushFinalBlock();       StringBuilder    ret  =  new    StringBuilder();     foreach(byte    b  in    ms.ToArray())       {        ret.AppendFormat("{0:X2}",    b);       }       ret.ToString();     return    ret.ToString();      }  ///MD5解密  public string MD5Decrypt(string    pToDecrypt,  string    sKey)    {      DESCryptoServiceProvider    des  =  new    DESCryptoServiceProvider();     byte[]    inputByteArray  =  new  byte[pToDecrypt.Length  /  2];     for(int    x  =  0;    x  <    pToDecrypt.Length  /  2;    x )       {      int    i  =    (Convert.ToInt32(pToDecrypt.Substring(x  *  2,  2),  16));        inputByteArray[x]  =    (byte)i;       }       des.Key  =    ASCIIEncoding.ASCII.GetBytes(sKey);       des.IV  =    ASCIIEncoding.ASCII.GetBytes(sKey);       MemoryStream    ms  =  new    MemoryStream();       CryptoStream    cs  =  new    CryptoStream(ms,    des.CreateDecryptor(),CryptoStreamMode.Write);       cs.Write(inputByteArray,  0,    inputByteArray.Length);       cs.FlushFinalBlock();       StringBuilder    ret  =  new    StringBuilder();                  return    System.Text.Encoding.Default.GetString(ms.ToArray());      }
    2013-11-13下载
    积分:1
  • C# Winform DataGridView 某一列中 呈现 树形控件 实例源码下载
    C# Winform DataGridView 某一列中 呈现 树形控件 实例源码下载
    2013-10-03下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载