惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy & Cybersecurity Law Blog
V
V2EX
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
Kaspersky official blog
S
Secure Thoughts
T
Tenable Blog
Security Latest
Security Latest
The Cloudflare Blog
S
Security @ Cisco Blogs
H
Heimdal Security Blog
aimingoo的专栏
aimingoo的专栏
TaoSecurity Blog
TaoSecurity Blog
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
IT之家
IT之家
Latest news
Latest news
The Hacker News
The Hacker News
C
Check Point Blog
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
N
News | PayPal Newsroom
Forbes - Security
Forbes - Security
P
Palo Alto Networks Blog
S
Security Affairs
S
Securelist
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
A
About on SuperTechFans

博客园 - 星星之火

Writing own regular expression parser How Regexes Work Content Based Routing Web Services in .NET and J2EE Poly-Engine Crypt String 绝不因寂寞而爱上别人 比尔·盖茨给青年一代的11点忠告 在.Net环境下用C#操纵活动目录 - 星星之火 - 博客园 谁能简单说一下活动目录是什么东西? 广播,多播(二)(Broadcasting, Multicasting) 两毛钱爽一把 可以建立一个Udp Server,接收发往本机所有端口的数据包吗? 广播,多播(一)(Broadcasting, Multicasting) C#异步网络编程 应该由国家建立非法网站数据库 use Helper Classes to simplify you network programming a udp echo server xml digital signature when udp goes bad and how to solve it(C#) when tcp goes bad, and how to solve it
a udp echo client
星星之火 · 2004-06-19 · via 博客园 - 星星之火

和我的UdpEchoServer配合使用,在本机上试验用。设定接收的时间限制是3秒。

/*
 * Created by SharpDevelop.
 * User: xuhx
 * Date: 2004-6-19
 * Time: 14:21
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace DefaultNamespace
{
 /// <summary>
 /// Description of Class1. 
 /// </summary>
 public class UdpEchoClient
 {
  private static readonly int BUF_SIZE=2048;
  
  public static void Main(){
   Socket clientSocket=new Socket(AddressFamily.InterNetwork,
                                  SocketType.Dgram,
                                  ProtocolType.Udp
                                  );
   clientSocket.SetSocketOption(SocketOptionLevel.Socket,
                                 SocketOptionName.ReceiveTimeout,
                                 3000
                                 );
   EndPoint serverEndPoint=new IPEndPoint(IPAddress.Parse("127.0.0.1"),
                                          8004
                                          );
   Console.WriteLine("echo client start");
   while(true){
    string input=Console.ReadLine();
    if("exit"==input.ToLower()){
     clientSocket.Close();
     Console.WriteLine("echo client stop.");
     break;
    }
    byte[] buf=Encoding.ASCII.GetBytes(input);
    clientSocket.SendTo(buf,SocketFlags.None,serverEndPoint);
    buf=new byte[BUF_SIZE];
    EndPoint remoteEndPoint=new IPEndPoint(IPAddress.Any,0);
    try{
     int receive=clientSocket.ReceiveFrom(buf,ref remoteEndPoint);
     string strReceive=Encoding.ASCII.GetString(buf,0,receive);
     Console.WriteLine("echoed from server: {0} message:{1}",remoteEndPoint,strReceive);
    }catch(SocketException e){
     Console.WriteLine(e.Message);
    }
   }//while
  }
 }
}