C#编程和网络编程入门
学习目标
-
用C#编写一个命令行/控制台hello world程序,实现如下功能:在屏幕上连续输出50行“hello cqjtu!重交物联2018级”;同时打开一个网络UDP 套接字,向室友电脑或树莓派发送这50行消息。
-
用VS2015/2017 的C#编写一个简单的Form窗口程序,有一个文本框 textEdit和一个发送按钮button,运行程序后,可以在文本框里输入文字,如“hello cqjtu!重交物联2018级”,点击button,将这些文字发送给室友电脑或树莓派,采用UDP套接字;
-
安装wireshark 抓包软件,抓取上述程序发送的网络包,对数据帧结构进行分析。
向室友电脑或树莓派发送50行消息
-
创建 一个控制台应用程序(.NET Core)
-
输入代码
using System;
namespace demo
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 50; i++)
{
Console.WriteLine("hello cqjtu!重交物联2018级");
}
Console.ReadLine();
}
}
}
- 输出结果
编写一个简单的Form窗口程序
- 创建项目文件在自己电脑里
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace Client
{
class Program
{
static void Main(string[] args)
{
//提示信息
Console.WriteLine("按下任意按键开始发送...")