资源简介
控制台程序,实现了本机连接
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
using System.Threading;
namespace UDP_Server
{
class Program
{
static Socket server;
static void Main(string[] args)
{
server = new Socket(AddressFamily.InterNetwork SocketType.Dgram ProtocolType.Udp);
server.Bind(new IPEndPoint(IPAddress.Parse(“127.0.0.1“) 2000));//绑定端口号和IP
Console.WriteLine(“服务端已经开启“);
Thread t = new Thread(ReciveMsg);//开启接收消息线程
t.Start();
Thread t2 = new Thread(sendMsg);//开启发送消息线程
t2.Start();
}
///
/// 向特定ip的主机的端口发送数据报
///
static void sendMsg()
{
EndPoint point = new IPEndPoint(IPAddress.Parse(“127.0.0.1“) 2000);
while (true)
{
string msg = Console.ReadLine();
server.SendTo(Encoding.UTF8.GetBytes(msg) point);
}
}
///
/// 接收发送给本机ip对应端口号的数据报
///
static void ReciveMsg()
{
while (true)
{
EndPoint point = new IPEndPoint(IPAddress.Any 0);//用来保存发送方的ip和端口号
byte[] buffer = new byte[1024];
int length = server.ReceiveFrom(buffer ref point);//接收数据报
string message = Encoding.UTF8.GetString(buffer 0 length);
Console.WriteLine(point.ToString() + message);
}
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 187 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\App.config
文件 5632 2020-12-11 22:49 ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe
文件 187 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe.config
文件 13824 2020-12-11 22:49 ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.pdb
文件 24224 2020-12-11 22:49 ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe
文件 187 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe.config
文件 490 2019-03-19 12:46 ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe.manifest
文件 2580 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.csproj
文件 688 2020-12-11 22:49 ConsoleApplication1\ConsoleApplication1\obj\Debug\ConsoleApplication1.csproj.FileListAbsolute.txt
文件 1755 2020-12-11 21:13 ConsoleApplication1\ConsoleApplication1\obj\Debug\ConsoleApplication1.csprojResolveAssemblyReference.cache
文件 5632 2020-12-11 22:49 ConsoleApplication1\ConsoleApplication1\obj\Debug\ConsoleApplication1.exe
文件 13824 2020-12-11 22:49 ConsoleApplication1\ConsoleApplication1\obj\Debug\ConsoleApplication1.pdb
文件 725 2020-12-11 21:27 ConsoleApplication1\ConsoleApplication1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6658 2020-12-11 19:10 ConsoleApplication1\ConsoleApplication1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 0 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
文件 1820 2020-12-11 22:49 ConsoleApplication1\ConsoleApplication1\Program.cs
文件 1362 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\Properties\AssemblyInfo.cs
文件 1026 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1.sln
..A..H. 30720 2020-12-11 21:37 ConsoleApplication1\ConsoleApplication1.v12.suo
目录 0 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\obj\Debug\TempPE
目录 0 2020-12-11 21:13 ConsoleApplication1\ConsoleApplication1\bin\Debug
目录 0 2020-12-11 22:49 ConsoleApplication1\ConsoleApplication1\obj\Debug
目录 0 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\bin
目录 0 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\obj
目录 0 2020-12-11 14:37 ConsoleApplication1\ConsoleApplication1\Properties
目录 0 2020-12-11 22:49 ConsoleApplication1\ConsoleApplication1
目录 0 2020-12-11 14:37 ConsoleApplication1
----------- --------- ---------- ----- ----
............此处省略2个文件信息
- 上一篇:SignalR在线聊天(websocket)
- 下一篇:使用Socket发送数据
相关资源
- c# udp通信例程(上位控制程序)
- 达梦数据库连接(基于DmProvider.dll)
- kepserver 连接 PLC代码
- tcp和udp(Mina.net)
- C#简单连接查询sqlite数据库
- C#连接SQL sever数据库有详细的注释,带
- udp通讯(需修改客户端链接服务端时
- LMI3D相机连接LMIHalconAcqTest.zip
- ASP.NET连接MYSQL的三种方法
- tcp+udp完全c#通信封装
- ODP.NET_Managed_ODAC122cR1
- C# 数据库连接MySQL、SQL server并读取数
- C#连接数据库..
- Asp.NET做的网上书店连接SQL SERVER数据库
- C#连接mysql数据库dll
- C# Asp.net简单通讯录
- 宏电DTU的DDP协议GPRS DSC中心源代码DE
- winform 员工管理 三层架构 实现了连接
- C#窗体程序结合oracle数据库完成的超市
- Aspose.Words.dll 和Aspose.Cells.dll,word、
- C#完整的通信代码(点对点点对多同步
- C#_UDP可靠文件传输
- C#连接MySQL数据库驱动类库
- C#写的UDP即时聊天程序
- c#仿QQ源代码附带数据库,QQ界面设计
- C# 基于UDP即时聊天程序源代码
- c#实现QQ聊天程序(源代码)(分服务
- MySQL安装教程+Visual Studio 2017 C#连接远
- WPF使用MQTTnet连接阿里云物联网平台
- C#UDP通信+文件传输 源码
评论
共有 条评论