资源简介
UDP 局域网异步通讯实现广播,接收发送string数据
用户就可以在一个局域网中聊天了。
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace Broadcast
{
public class Broadcast
{
static Socket sockReceive;
static byte[] buff;
static EndPoint ep;
public Broadcast() {
buff=new byte[8192];
sockReceive = new Socket(AddressFamily.InterNetwork
SocketType.Dgram ProtocolType.Udp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any 9050);
sockReceive.Bind(iep);
ep = (EndPoint)iep;
sockReceive.BeginReceiveFrom(buff 0 buff.Length SocketFlags.None ref ep new AsyncCallback(CallReceive) sockReceive);
}
private void CallReceive(IAsyncResult ar)
{
Socket sock = (Socket)ar.AsyncState;
try
{
sock.Blocking = true;
ar.AsyncWaitHandle.WaitOne();
if (ar.IsCompleted)
{
int i = sock.EndReceiveFrom(ar ref ep);
Console.Write(Encoding.ASCII.GetString(buff 0 i) + “\n“);
}
sock.Blocking = false;
}
catch (SocketException soketEx)
{
throw soketEx;
}
finally
{
sock.BeginReceiveFrom(buff 0 buff.Length SocketFlags.None ref ep CallReceive sock);
}
}
public void Close() {
sockReceive.Close();
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5632 2011-05-30 15:10 Broadcast\Broadcast\bin\Debug\Broadcast.vshost.exe
文件 1621 2011-05-30 14:56 Broadcast\Broadcast\Broadcast.cs
文件 3305 2011-05-30 14:44 Broadcast\Broadcast\Broadcast.csproj
文件 1373 2011-05-30 15:10 Broadcast\Broadcast\Form1.cs
文件 2097 2011-05-30 15:09 Broadcast\Broadcast\Form1.Designer.cs
文件 5814 2011-05-30 15:09 Broadcast\Broadcast\Form1.resx
文件 476 2011-05-30 14:45 Broadcast\Broadcast\Program.cs
文件 1284 2011-05-30 11:29 Broadcast\Broadcast\Properties\AssemblyInfo.cs
文件 2847 2011-05-30 11:29 Broadcast\Broadcast\Properties\Resources.Designer.cs
文件 5612 2011-05-30 11:29 Broadcast\Broadcast\Properties\Resources.resx
文件 1094 2011-05-30 11:29 Broadcast\Broadcast\Properties\Settings.Designer.cs
文件 249 2011-05-30 11:29 Broadcast\Broadcast\Properties\Settings.settings
文件 1688 2011-05-30 14:10 Broadcast\Broadcast.sln
..A..H. 17920 2011-05-30 15:10 Broadcast\Broadcast.suo
文件 3219 2011-05-30 14:10 Broadcast\Client\Client.csproj
文件 1213 2011-05-30 15:09 Broadcast\Client\Form1.cs
文件 2562 2011-05-30 15:09 Broadcast\Client\Form1.Designer.cs
文件 5814 2011-05-30 15:09 Broadcast\Client\Form1.resx
文件 473 2011-05-30 13:53 Broadcast\Client\Program.cs
文件 1278 2011-05-30 13:53 Broadcast\Client\Properties\AssemblyInfo.cs
文件 2841 2011-05-30 13:53 Broadcast\Client\Properties\Resources.Designer.cs
文件 5612 2011-05-30 13:53 Broadcast\Client\Properties\Resources.resx
文件 1091 2011-05-30 13:53 Broadcast\Client\Properties\Settings.Designer.cs
文件 249 2011-05-30 13:53 Broadcast\Client\Properties\Settings.settings
目录 0 2011-05-30 11:29 Broadcast\Broadcast\obj\Debug\TempPE
目录 0 2011-05-30 13:53 Broadcast\Client\obj\Debug\TempPE
目录 0 2011-05-30 15:10 Broadcast\Broadcast\bin\Debug
目录 0 2011-05-30 15:09 Broadcast\Broadcast\obj\Debug
目录 0 2011-05-30 15:10 Broadcast\Client\bin\Debug
目录 0 2011-05-30 15:10 Broadcast\Client\obj\Debug
............此处省略12个文件信息
相关资源
- C#UDP实现停等协议
- 实现UDP可靠文件传输
- C#开发的网络调试助手包括TCP和UDP客户
- C#实现异步拷贝多个文件
- C# UDP广播+委托+网络调试助手
- C# Socket异步通信+通信与界面分离处理
- [免积分]C# Socket 异步双工通讯
- C#中的TCP和UDP通信的实现
- c# socket(udp/tcp) demo
- 异步串行串口通讯C#RS232
- C# tcpudp服务器,客户端
- udp打洞源码服务端和客户端C# 实现
- C#UDP屏幕监控
- C# UDPSocket异步传输文件
- C# TCP异步数据传输
- c# socket 异步通信,一个服务器端和多
- 网际校验和算法ICMP、TCP、UDP
- winform 多线程 异步 文件操作(查询、
- Winform DataGridView中利用WebClient异步加载
- C# udp服务器收发、点对点收发
- Winform C#Socket异步通信
- C#实现Socket编程 (异步通讯解决Tcp粘
- c# scoket异步通信代码
- C#UDP通信+文件传输
- WPF TreeView递归异步绑定
- c#监听指定端口的UDP信息
- C# TCP/IP异步通信
- Loading 动画+数据异步调用多线程
- C# 利用remoting制作局域网简单聊天室
- C# 文件传输 UDP
评论
共有 条评论