当前位置: 首页 > news >正文

wordpress 站内资讯天元建设集团有限公司图片

wordpress 站内资讯,天元建设集团有限公司图片,连云港企业建站 网站,四川仁厚建设集团有限公司概述所谓套接字(Socket)#xff0c;就是对网络中不同主机上的应用进程之间进行双向通信的端点的抽象。一个套接字就是网络上进程通信的一端#xff0c;提供了应用层进程利用网络协议交换数据的机制。从所处的地位来讲#xff0c;套接字上联应用进程#xff0c;下联网络协议… 概述所谓套接字(Socket)就是对网络中不同主机上的应用进程之间进行双向通信的端点的抽象。一个套接字就是网络上进程通信的一端提供了应用层进程利用网络协议交换数据的机制。从所处的地位来讲套接字上联应用进程下联网络协议栈是应用程序通过网络协议进行通信的接口是应用程序与网络协议根进行交互的接口。套接字是通信的基石是支持TCP/IP协议的路通信的基本操作单元。可以将套接字看作不同主机间的进程进行双间通信的端点它构成了单个主机内及整个网络间的编程界面。套接字存在于通信域中通信域是为了处理一般的线程通过套接字通信而引进的一种抽象概念。套接字通常和同一个域中的套接字交换数据(数据交换也可能穿越域的界限但这时一定要执行某种解释程序)各种进程使用这个相同的域互相之间用Internet协议簇来进行通信。Socket(套接字)可以看成是两个网络应用程序进行通信时各自通信连接中的端点这是一个逻辑上的概念。它是网络环境中进程间通信的API(应用程序编程接口)也是可以被命名和寻址的通信端点使用中的每一个套接字都有其类型和一个与之相连进程。通信时其中一个网络应用程序将要传输的一段信息写入它所在主机的 Socket中该 Socket通过与网络接口卡(NIC)相连的传输介质将这段信息送到另外一台主机的 Socket中使对方能够接收到这段信息。Socket是由IP地址和端口结合的提供向应用层进程传送数据包的机制。服务端using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using System.Windows.Forms;namespace SocketForm {public partial class Form1 : Form{public Form1(){InitializeComponent();}private void bt_connnect_Click(object sender, EventArgs e){try{//点击开始监听时 在服务端创建一个负责监听IP和端口号的SocketSocket socketWatch  new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);IPAddress ip  IPAddress.Any;//创建对象端口IPEndPoint point  new IPEndPoint(ip, Convert.ToInt32(tb_port.Text));socketWatch.Bind(point);//绑定端口号ShowMsg(监听成功!);socketWatch.Listen(10);//设置监听//创建监听线程Thread thread  new Thread(Listen);thread.IsBackground  true;thread.Start(socketWatch);}catch { }}/// summary/// 等待客户端的连接 并且创建与之通信的Socket/// /summarySocket socketSend;void Listen(object o){try{Socket socketWatch  o as Socket;while (true){socketSend  socketWatch.Accept();//等待接收客户端连接ShowMsg(socketSend.RemoteEndPoint.ToString()  :  连接成功!);//开启一个新线程执行接收消息方法Thread r_thread  new Thread(Received);r_thread.IsBackground  true;r_thread.Start(socketSend);}}catch { }}/// summary/// 服务器端不停的接收客户端发来的消息/// /summary/// param nameo/paramvoid Received(object o){try{Socket socketSend  o as Socket;while (true){//客户端连接服务器成功后服务器接收客户端发送的消息byte[] buffer  new byte[1024 * 1024 * 3];//实际接收到的有效字节数int len  socketSend.Receive(buffer);if (len  0){break;}string str  Encoding.UTF8.GetString(buffer, 0, len);ShowMsg(socketSend.RemoteEndPoint  :  str);}}catch { }}/// summary/// 服务器向客户端发送消息/// /summary/// param namestr/paramvoid Send(string str) {byte[] buffer  Encoding.UTF8.GetBytes(str);socketSend.Send(buffer);}void ShowMsg(string msg){listBox1.Items.Add(msg  \r\n);}private void Form1_Load(object sender, EventArgs e){Control.CheckForIllegalCrossThreadCalls  false;}private void bt_send_Click(object sender, EventArgs e){Send(txt_msg.Text.Trim());}} }客户端using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using System.Windows.Forms;namespace SocketClient {public partial class Form1 : Form{public Form1(){InitializeComponent();}Socket socketSend;private void bt_connect_Click(object sender, EventArgs e){try{//创建客户端Socket获得远程ip和端口号socketSend  new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);IPAddress ip  IPAddress.Parse(txt_ip.Text);IPEndPoint point  new IPEndPoint(ip, Convert.ToInt32(txt_port.Text));socketSend.Connect(point);ShowMsg(连接成功!);//开启新的线程不停的接收服务器发来的消息Thread c_thread  new Thread(Received);c_thread.IsBackground  true;c_thread.Start();}catch (Exception){ShowMsg(IP或者端口号错误...);}}void ShowMsg(string str){textBox1.AppendText(str  \r\n);}/// summary/// 接收服务端返回的消息/// /summaryvoid Received(){while (true){try{byte[] buffer  new byte[1024 * 1024 * 3];//实际接收到的有效字节数int len  socketSend.Receive(buffer);if (len  0){break;}string str  Encoding.UTF8.GetString(buffer, 0, len);ShowMsg(socketSend.RemoteEndPoint  :  str);}catch { }}}/// summary/// 向服务器发送消息/// /summary/// param namesender/param/// param namee/paramprivate void bt_send_Click(object sender, EventArgs e){try{string msg  txt_msg.Text.Trim();byte[] buffer  new byte[1024 * 1024 * 3];buffer  Encoding.UTF8.GetBytes(msg);socketSend.Send(buffer);}catch { }}private void Form1_Load(object sender, EventArgs e){Control.CheckForIllegalCrossThreadCalls  false;}} }
http://www.pierceye.com/news/809806/

相关文章:

  • 电商网站建设 解决方案的设计营销策略都有哪些方面
  • 菏泽网站建设兼职凡科网制作网站教程
  • 实验一 电子商务网站建设与维护北京网站设计培训学校
  • 周到的网站建设合肥建筑网站大全
  • 国外互联网资讯网站南宁网站制作费用
  • 建设公司网站要注意哪些蜜雪冰城推广软文
  • 做信息安全的网站博客网站的建设
  • 门户网站建设项目书提升学历是什么意思
  • 上海网站建设极简慕枫塘沽有哪些互联网公司
  • 社区网站如何做官方网站建设哪儿有
  • 做兼职的网站策划书大连中山网站建设
  • 中国摄影网站深圳网站建设龙华
  • 个人网站怎么建立深圳网站建站费用
  • 笔趣阁建站教程网页设计 网站建设啥意思
  • 海门网站开发西安响应式网站建设服务提供商
  • 自适应网站建站哈尔滨市建设安全监察网站
  • nas服务器可以做网站吗电商类网站开发方案
  • 免费的个人的网站网站建设 考虑
  • 医院网站建设的目的高端网站有哪些优势
  • 佛山网站建设首选如何备份wordpress
  • 优化稳定网站排名网站建设需要学什么语言
  • 可以做设计私单的网站硬件开发工程师面试
  • 竞价网站单页网页设计师中级证书有用吗
  • 做网站 简单外包wordpress 插件api
  • 白城网站seo新手怎么建立自己网站
  • 建立用模板建立网站wordpress feed
  • 株洲品牌网站建设优质的杭州网站优化
  • 网站开发在哪个科目核算网站平台怎么做的好处
  • 网站底部模板代码江苏建站系统
  • 写出网站开发的基本流程品牌建设网站