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

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Latest news
Latest news
B
Blog RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
博客园 - Franky
博客园_首页
爱范儿
爱范儿
博客园 - 聂微东
月光博客
月光博客
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
IT之家
IT之家
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
Scott Helme
Scott Helme
The Hacker News
The Hacker News
Jina AI
Jina AI
V
Visual Studio Blog
小众软件
小众软件
WordPress大学
WordPress大学
N
News and Events Feed by Topic
L
Lohrmann on Cybersecurity
P
Privacy International News Feed
美团技术团队
D
Darknet – Hacking Tools, Hacker News & Cyber Security
宝玉的分享
宝玉的分享
Spread Privacy
Spread Privacy
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Hacker News: Ask HN
Hacker News: Ask HN
雷峰网
雷峰网
Martin Fowler
Martin Fowler
C
Cybersecurity and Infrastructure Security Agency CISA
A
Arctic Wolf
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
N
News and Events Feed by Topic

博客园 - 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