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

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

于 2020-05-31 发布
0 196
下载积分: 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 个回复

  • asp.net 视频播放网站源码(含数据库)
    asp.net sql server数据库,视频播放网站源码
    2021-05-06下载
    积分:1
  • 猴子选大王示例代码
    猴子选大王示例代码
    2015-01-23下载
    积分:1
  • C# 套打Demo
    套打Demo 【核心代码】using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Drawing.Printing;namespace Print_Demo{ public partial class Form1 : Form { public PrintDocument printDt = new PrintDocument(); //打印文档对象 Font printFont; //打印使用的字体 public Form1() { InitializeComponent(); } void printDt_PrintPage(object sender, PrintPageEventArgs e) { float pointX = 10; float pointY = 10; e.Graphics.DrawString("打印内容", new Font("宋体", 16F), Brushes.Black, pointX 60, pointY); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 26,pointX 300,pointY 26); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 35); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 56, pointX 300, pointY 56); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 65); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 86, pointX 300, pointY 86); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 95); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 116, pointX 300, pointY 116); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 125); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 146, pointX 300, pointY 146); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 155); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 176, pointX 300, pointY 176); e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 185); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 206, pointX 300, pointY 206); e.Graphics.DrawString("检测结果", printFont, Brushes.Black, pointX, pointY 233); e.Graphics.DrawString("通过", new Font("宋体",22F,FontStyle.Bold), Brushes.Black, pointX 90, pointY 225); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 265, pointX 300, pointY 265); e.Graphics.DrawString("单位名称", printFont, Brushes.Black, pointX, pointY 275); } private void Form1_Load(object sender, EventArgs e) { printDt.PrintPage = new PrintPageEventHandler(printDt_PrintPage); printFont = new Font("宋体", 12F); } private void btnPrint_Click(object sender, EventArgs e) { //PrintDialog printDlg = new PrintDialog(); //printDlg.Document = printDt; //printDlg.AllowPrintToFile = true; //printDlg.AllowCurrentPage = true; //printDlg.AllowSelection = true; //printDlg.ShowDialog(); //printDlg.ShowDialog(); printDt.Print(); } private void btnLook_Click(object sender, EventArgs e) { PrintPreviewDialog printPreview = new PrintPreviewDialog(); printPreview.PrintPreviewControl.Document = printDt; printPreview.ShowDialog(this); } }}
    2021-05-06下载
    积分:1
  • 大家一起学鸿蒙OS(HarmonyOS)设备开发教程
    【实例简介】
    2021-11-04 00:30:53下载
    积分:1
  • 求平均值以及a类不确定度的代码程序
    求平均值以及a类不确定度的代码程序
    2016-10-26下载
    积分:1
  • c# 创建桌面快捷方式 开始菜单显示 将网页添加到收藏夹 附完整实例
    快捷方式,收藏夹,开始菜单 完整代码                                           
    2013-07-14下载
    积分:1
  • c# 获取当前系统所有窗口句柄(含任务栏/托盘图标等) 完整源码下载
    c# 获取当前系统所有窗口句柄(含任务栏/托盘图标等) 完整源码下载
    2013-09-14下载
    积分:1
  • 用于解决著名的奶牛问题
    该算法用于解决著名的奶牛问题
    2013-08-13下载
    积分:1
  • C#操作Access数据库源码
            基于SQL语句新建,添加,查找,等操作
    2015-01-30下载
    积分:1
  • C# RadioListBox 多选框示例源码
    C# RadioListBox 多选框示例源码
    2013-10-02下载
    积分:1
  • 696516资源总数
  • 106927会员总数
  • 1今日下载