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

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
Intezer
C
Cyber Attacks, Cyber Crime and Cyber Security
The Register - Security
The Register - Security
量子位
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
MyScale Blog
MyScale Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
Jina AI
Jina AI
博客园 - 【当耐特】
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
SecWiki News
SecWiki News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
G
GRAHAM CLULEY
宝玉的分享
宝玉的分享
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
有赞技术团队
有赞技术团队
T
Tor Project blog
H
Hacker News: Front Page
A
Arctic Wolf
NISL@THU
NISL@THU
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
V
V2EX
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
I
InfoQ
D
Docker
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42

博客园 - Gofficer

决战紫禁之巅 为学 C#网页自动登录和提交POST信息的多种方法 一个C#写的调用外部进程类 快速实现在Windows应用程序中支持拖拽的TreeView控件(C#) PPT转图片 开发人员,敢问路在何方? C# 实现注销、关机、重启电脑功能 ultraGrid 控件中,实现单元格内容换行显示 如何用一条sql取得第10到第20条的记录? 用Sandcastle一键生成CHM帮助文档 实现服务器端与客户端对话 C#中访问WEB页面 使用代理服务器 自定义Ping方法 HTTP请求和应答 Socket套接字实现服务器端连接 启动和停止本地系统进程 异常处理
Socket套接字实现客户端连接
Gofficer · 2007-08-24 · via 博客园 - Gofficer

  1using System;
  2using System.Drawing;
  3using System.Collections;
  4using System.ComponentModel;
  5using System.Windows.Forms;
  6using System.Data;
  7// 新添加的命名空间。
  8using System.Net;
  9using System.Net.Sockets;
 10using System.Text;
 11using System.IO;
 12
 13namespace SocketClient
 14{
 15    /// <summary>
 16    /// Socket套接字实现客户端连接。
 17    /// </summary>

 18    public class Form1 : System.Windows.Forms.Form
 19    {
 20        private System.Windows.Forms.Button button1;
 21        private System.Windows.Forms.RichTextBox richTextBox1;
 22        /// <summary>
 23        /// 必需的设计器变量。
 24        /// </summary>

 25        private System.ComponentModel.Container components = null;
 26
 27        public Form1()
 28        {
 29            //
 30            // Windows 窗体设计器支持所必需的
 31            //
 32            InitializeComponent();
 33
 34            //
 35            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
 36            //
 37        }

 38
 39        /// <summary>
 40        /// 清理所有正在使用的资源。
 41        /// </summary>

 42        protected override void Dispose( bool disposing )
 43        {
 44            if( disposing )
 45            {
 46                if (components != null)
 47                {
 48                    components.Dispose();
 49                }

 50            }

 51            base.Dispose( disposing );
 52        }

 53
 54        Windows Form Designer generated code
 96
 97        /// <summary>
 98        /// 应用程序的主入口点。
 99        /// </summary>

100        [STAThread]
101        static void Main()
102        {
103            Application.Run(new Form1());
104        }

105
106        private void button1_Click(object sender, System.EventArgs e)
107        {
108            // 服务器IP地址
109            IPAddress        serIP;
110            // 服务器节点
111            IPEndPoint        server;
112            // 客户端Socket
113            Socket            client;
114            // 客户端网络数据流
115            NetworkStream    stream;
116            // 客户端写数据流
117            TextWriter        writer;
118            // 客户端读数据流
119            TextReader        reader;
120
121            serIP = IPAddress.Parse("218.66.48.230");
122            server = new IPEndPoint(serIP,34567);
123            client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
124            client.Connect(server);
125            if(client.Connected)
126            {
127                stream = new NetworkStream(client);
128                writer = new StreamWriter(stream);
129                reader = new StreamReader(stream);
130                richTextBox1.Text += "连接到服务器\n";
131                richTextBox1.Text += reader.ReadLine();
132                richTextBox1.Text += reader.ReadLine();
133                richTextBox1.Text += "\n";
134                writer.WriteLine("你好,服务器,很高兴能和你通讯,谢谢。");
135                writer.Flush();
136                reader.Close();
137                writer.Close();
138                stream.Close();
139                client.Close();
140            }

141        }

142    }

143}

144