Socket协议通讯

 

服务器端代码:

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 Server
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public List<Socket> serverSockeList = new List<Socket>();
Socket serverSocke = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
bool kg=true;
string recStr = "";
byte[] recByte = new byte[1000];
int bytes = 0;
delegate void invokeInfo(string obj);
private void But_Starlisten_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txt_IP.Text) || string.IsNullOrEmpty(txt_port.Text))
return;
IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(txt_IP.Text), int.Parse(txt_port.Text));
serverSocke.Bind(ipe);
serverSocke.Listen(10000);
txt_MessageLog.Text += "监听已经打开,请等待\r\n"; Thread conn = new Thread(new ParameterizedThreadStart(GetALLClientConn));
conn.IsBackground = true;
conn.Start(serverSocke);
}
catch (Exception ex)
{
txt_MessageLog.Text += "服务异常\r\n";
}
} /// <summary>
/// 关闭所有的Socket协议和线程
/// </summary>
public void Close()
{
try
{
kg = false;
foreach (var item in serverSockeList)
{
if (item.Connected)
item.Shutdown(SocketShutdown.Both);
if (item != null)
item.Close();
}
if (serverSocke.Connected)
serverSocke.Shutdown(SocketShutdown.Both);
if (serverSocke != null)
serverSocke.Close();
}
catch {
txt_MessageLog.Text += "服务器连接关闭\r\n";
}
} /// <summary>
/// 获取所有客户端连接
/// </summary>
/// <param name="obj">客户端Socket对象</param>
public void GetALLClientConn(object obj)
{
Socket serverSocke = obj as Socket;
try
{
while (kg)
{
Socket newSocket = serverSocke.Accept();
serverSockeList.Add(newSocket);
txt_MessageLog.Invoke(new invokeInfo(Output), newSocket.RemoteEndPoint + "连接已经建立");
Thread t = new Thread(new ParameterizedThreadStart(GetInfo));
t.IsBackground = true;
t.Start(newSocket);
}
}
catch {
txt_MessageLog.Invoke(new invokeInfo(Output), "服务器异常"); }
} /// <summary>
/// 获取该Socket对象的信息
/// </summary>
/// <param name="newSocket">Socket对象</param>
public void GetInfo(object obj)
{
Socket newSocket = obj as Socket;
try
{
while (kg)
{ bytes = newSocket.Receive(recByte, recByte.Length, SocketFlags.None); if (bytes <= 0)
{
txt_MessageLog.Invoke(new invokeInfo(Output), newSocket.RemoteEndPoint + "连接已断开");
serverSockeList.Remove(newSocket);
if (newSocket.Connected)
newSocket.Shutdown(SocketShutdown.Both);
newSocket.Disconnect(false);
newSocket.Close();
break;
}
recStr = Encoding.UTF8.GetString(recByte, 0, bytes);
txt_MessageLog.Invoke(new invokeInfo(Output), recStr);
byte[] sendBytes = Encoding.UTF8.GetBytes(recStr);
foreach (var item in serverSockeList)
{
if (item != newSocket)
item.Send(sendBytes);
}
}
}
catch (Exception ex)
{
txt_MessageLog.Invoke(new invokeInfo(Output), newSocket.RemoteEndPoint + "的信息接收异常");
}
} public void Output(string info)
{
txt_MessageLog.Text += info + "\r\n";
} //发送信息
private void But_Send_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txt_Send.Text))
return;
string sendStr = txt_Send.Text;
txt_Send.Text = "";
txt_MessageLog.Text += "服务端信息:" + sendStr + "\r\n";
byte[] sendBytes = Encoding.UTF8.GetBytes("服务端信息:" + sendStr);
Socket error = null;
foreach (var item in serverSockeList)
{
if (item.Poll(-1,SelectMode.SelectWrite))
item.Send(sendBytes);
else
error = item;
}
if (error != null)
serverSockeList.Remove(error);
}
catch (Exception ex)
{
txt_MessageLog.Text += "服务端发送信息异常\r\n";
}
} private void But_endlisten_Click(object sender, EventArgs e)
{
Close();
} private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Close();
}
}
}

服务器端界面:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAh8AAAGNCAIAAAA+eYRTAAAgAElEQVR4nO3da3QUZb7v8Xp1Zs6cM2vP2Sdnttvli72y9kbnKC8kuta+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4Zmy4nNTEMQ96I33Uu8FgzeqRLJiNdAP0yM136+vpO6GAYhsdd20750aQrR6Ovr490yVikC6BfxqZLzagZhiFvW3fjG7Zltp1J94wG6ZLJSBdAv8xMl97e3m80seLEbWf81o2ul9Hb20u6ZCzSBdAvY9PlyPhCumQy0gXQLzPTpaen5/D40tPTQ7pkLNIF0C8D0yUUCjU2NkYikUPjRSQSaWxs5Pe7ZCzSBdAvA9Nl+fLl5eXlzc3NPeNFc3NzeXn5cn43ZaYiXQD9MjBdotHo0qVLQ6HQmPyO+3QIhUJLly5N90WFK9IF0C8z0wVIJdIF0I90AUgXQD/SBSBdAP1IF4B0AfQjXQDSBdCPdAFIF0A/0gUgXQD9SBeAdAH0I10A0gXQj3QBSBdAP9IFIF0A/UgXgHQB9CNdANIF0I90AUgXQD/SBSBdAP1IF4B0AfQjXQDSBdCPdAFIF0A/0gUgXQD9SBeAdAH0I10A0gXQj3QBSBdAP9IFIF0A/UgXgHQB9CNdANIF0I90AUgXQD/SBSBdAP1IF4B0AfQjXQDSBdCPdAFIF0A/0gUgXQD9SBeAdAH0I10A0gXQj3QBSBdAP9IFIF0A/UgXgHQB9CNdANIF0I90AUgXQD/SBSBdAP1IF4B0AfQjXYBRpUt7JJrmL2Ig87RHoqQLMPJ0CYe7mtrPMgzjnHC4K0q6ILcFTpehoSG+YAA/jtW3DA0NpftVAOkROF2i0agVMAzDeA/Rglw2knSJRvlxC6CW3q9tIL0U6bL9cAfDMAzDjH4uO9RMujAMwzCah3RhGIZh9A/pwjAMw+gf0oVhGIbRP6QLwzAMo3+G0+WyQ80MwzAMo2supAsAAHr19/cb/QAA6Pb/AcINnatJE6teAAAAAElFTkSuQmCC" alt="" />

------------------------------------------------------------------------------------------

客户端代码:

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.Windows.Forms;
using System.Threading; namespace Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public Socket clientSocket;
bool kg = true;
delegate void invokeInfo(string obj);
string recStr = "";
byte[] recBytes = new byte[4096];
int bytes = 0;
public void Output(string info)
{
txt_MessageLog.Text += info + "\r\n";
} private void But_Send_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txt_Send.Text))
return;
string sendStr = txt_Send.Text;
txt_Send.Text = "";
txt_MessageLog.Text += "我:" + sendStr + "\r\n";
byte[] sendBytes = Encoding.UTF8.GetBytes(clientSocket.RemoteEndPoint + ":" + sendStr);
int i= clientSocket.Send(sendBytes);
}
catch (Exception ex)
{
txt_MessageLog.Text += "信息发送异常\r\n";
}
} private void But_Starlisten_Click(object sender, EventArgs e)
{
try
{ clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
if (string.IsNullOrEmpty(txt_IP.Text) || string.IsNullOrEmpty(txt_port.Text))
return;
IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(txt_IP.Text), int.Parse(txt_port.Text));
clientSocket.Connect(ipe);
txt_MessageLog.Text += "连接成功\r\n";
groupBox1.Text += txt_IP.Text;
Thread t = new Thread(new ParameterizedThreadStart(GetInfo));
t.IsBackground = true;
t.Start(clientSocket); }
catch (Exception ex)
{
txt_MessageLog.Text += "服务器连接异常\r\n";
}
} private void But_endlisten_Click(object sender, EventArgs e)
{
Close();
} private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Close();
} /// <summary>
/// 接收服务端信息
/// </summary>
public void GetInfo(object o)
{
Socket clientSocket = o as Socket;
try
{
while (kg)
{
bytes = clientSocket.Receive(recBytes, recBytes.Length, SocketFlags.None);
if (bytes <= 0)
{
txt_MessageLog.Invoke(new invokeInfo(Output), "服务器连接已经关闭");
if (clientSocket.Connected)
clientSocket.Shutdown(SocketShutdown.Both);
clientSocket.Disconnect(false);
clientSocket.Close();
break;
}
recStr = Encoding.UTF8.GetString(recBytes, 0, bytes);
txt_MessageLog.Invoke(new invokeInfo(Output), recStr);
}
}
catch (Exception ex)
{
txt_MessageLog.Invoke(new invokeInfo(Output), "服务器的信息接收异常,原因:" + ex.Message+"\r\n");
}
} /// <summary>
/// 关闭Socket
/// </summary>
public void Close()
{
try
{
kg = false;
if (clientSocket.Connected)
clientSocket.Shutdown(SocketShutdown.Both);
clientSocket.Close();
}
catch { }
} }
}

客户端界面:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAh4AAAGQCAIAAABu8/4oAAAft0lEQVR4nO3dfXRU9Z348fvXttvf9mx3f1nXdfljT84u2271jxo8Z5/anmNcPWLVtdmNsq1Sn9KtbSFUhlSL6NpTiCIksbISENHiQxVrt1VrIQKXBxXECiSQECAGwoQ8AmOe9pxk6Hf/mMydmzvf+52bz0wyd8L7dT4n586d78ydXMh9O4kaa2RkZGRkZA4AAJM3a9asSy+9dGQia86cOVdfffWWLVtOnz6tAACYjHg8fryn/y9L5xZdckkqLTU1NdFodO2bBxmGYRhGNo2x/32l+aRTFysajda/eYhhGIZhspmd54Zn/ds3xtNS/9YhhmEYhsl+Xu8ZSvzcxVr3m0aGYRiGyX5e7RmeNWvWyMiItf7tJoZhGIbJfl7qGpozZ87IyIi14beHGYZhGCb7ef5MMi3PbjnMMAzDMNnPM53JtGzc2swwDMMw2c/T0eHxtDzf0MIwDMM4U/fqnu89Un/7wurczvceqa97dc+0HeK5l965/cs3lhYV53Zu//KNz730jt+pe7JjKHNa7MDy/leBYRgmV3Pvktotuw+2dw/kdrbsPnjvktppO8TNs6/aum79UNOHuZ2t69bfPPsqv1OXSsvP3jnqN7Zte24eeeGyxBx6/i/2P/Pn7629ZPuTRZ5lDMMwBT3zKx9r7x7Yfbgrt9PePTC/8rFpO0RpUfHgoQ96XnkmtzN46IPSomK/U7fqVDItL2xv9Rvbtj03j7xw2e/7t/y+f8vve16/0PnchVOrfrXiTzzL0mbrN79oXb3CsCCx5kvf3KS5K/I172NXffdLmZ6NYRhGPt9a9PjHXQM7m7pyOx93DXxr0ePTdojSouKBj/Z2v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iOtHfG4/F8vwogdCaXllgslqgLwzBH6ArgY9JpicX4EQswLr9fvUBomdKy5VAvwzAMw2Q/nz8QJS0MwzBMLoe0MAzDMDke0sIwDMPkeEgLwzAMk+MhLQzDMEyOJ5WWzx+IMgzjN9ZEeX89DBPysQBk5PlvXPL9coCwG/9KGQHgw9KlJd8vCggv50vm/wAEcpy8zE/S8gAAAABJRU5ErkJggg==" alt="" />

客户端代码:

Socket协议通讯的更多相关文章

  1. [dotnet core]使用Peach简化Socket网络通讯协议开发

    Peach是基于DotNetty的Socket网络通讯帮助类库,可以帮助开发者简化使用DotNetty,关于DotNetty可参考我之前的这篇文章. Peach内置实现了一个基于文本协议的Comman ...

  2. Socket网络通讯开发总结之:Java 与 C进行Socket通讯 + [备忘] Java和C之间的通讯

    Socket网络通讯开发总结之:Java 与 C进行Socket通讯 http://blog.sina.com.cn/s/blog_55934df80100i55l.html (2010-04-08 ...

  3. 第五十三节,socket模块介绍,socket单线程通讯

    socket单线程通讯,只能单线程通讯,不能并发 socket是基于(TCP.UDP.IP)的通讯.也叫做套接字 通讯过程由服务端的socket处理信息发送,由客户端的socket处理信息接收. so ...

  4. Socket协议

    Socket协议的形象描述 socket的英文原义是"孔"或"插座".在这里作为4BDS UNIX的进程通信机制,取后一种意思.socket非常类似于电话插座. ...

  5. Loadrunner 中socket协议RecvBuffer接收到数据长度为空

    socket通讯,有两种方式,一种是建立长连接(TCP),建立后,不停的发送,接收.另外一种是建立短连接(UDP),建立连接,发送报文,接收响应,关闭连接.两种方式 server的开销不同. 今天出现 ...

  6. TCP UDP Socket 即时通讯 API 示例 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  7. TCP协议通讯工作原理

    TCP协议通讯工作原理   一.TCP三次握手 传输控制协议(Transport Control Protocol)是一种面向连接的,可靠的传输层协议.面向连接是指一次正常的TCP传输需要通过在TCP ...

  8. loadrunner socket协议问题归纳(6)

    首先让我们先看一下loadrunner- winsock 函数 一览表: lrs_accept_connection 接受侦听套接字连接 lrs_close_socket 关闭打开的套接字       ...

  9. loadrunner socket协议问题归纳(3)

    摘要:通过实例讲解loadrunner中的socket协议性能测试的一种测试方法,如何不依赖loadrunner既定规则,自行控制收发数据包 关键词:Loadrunner,socket,自行控制,收发 ...

随机推荐

  1. centos 搭建ntp

    str=$(printf "%-25s" "*") echo -e "${str// /*}" echo -e "*\t\t\t* ...

  2. 7.添加OpenStack计算服务

    添加计算服务 安装和配置控制器节点 创建数据库 mysql -uroot -ptoyo123 CREATE DATABASE nova; GRANT ALL PRIVILEGES ON nova.* ...

  3. 关于JAVA SESSION的小测试

    手生就要多练啊... package com.jeelearning.servlet; import java.io.IOException; import java.io.PrintWriter; ...

  4. 牛客小白月赛3 I 排名【结构体排序/较复杂/细节】

    链接:https://www.nowcoder.com/acm/contest/87/I 来源:牛客网 题目描述 Cwbc和XHRlyb都参加了SDOI2018,他们特别关心自己的排名. 我们定义每一 ...

  5. TCC分布式事务的实现原理(转载 石杉的架构笔记)

    拜托,面试请不要再问我TCC分布式事务的实现原理![石杉的架构笔记] 原创: 中华石杉 目录 一.写在前面 二.业务场景介绍 三.进一步思考 四.落地实现TCC分布式事务 (1)TCC实现阶段一:Tr ...

  6. [POJ 1935] Journey

    Link: POJ1935 传送门 Solution: 一道吓唬人的水题 注意这是一棵树,两点间仅有唯一的路径! 于是每个“关键点”和起点只有一条路径,想去起点另一棵子树上的节点必须要回到起点 如果必 ...

  7. [COCI2017-2018 Contest5] Birokracija

    题目描述 Mirko has become CEO of a huge corporation. This corporation consists of ​N people, labeled fro ...

  8. POJ 3713 Transferring Sylla (三连通图)

    [题目链接] http://poj.org/problem?id=3713 [题目大意] 给出一个图判断是不是三连通图,三连通图的意思是对于图中任意两点, 至少有三条路是可以相互连通的. [题解] 我 ...

  9. SQL常用函数之五 str()

    原文:SQL常用函数之五 str() 使用str函数   :STR 函数由数字数据转换来的字符数据.   语法      STR    (    float_expression    [    ,  ...

  10. Asp.net+EF

    EFRepositoryBase using System; using System.Collections.Generic; using System.Data; using System.Dat ...