c#Socket通讯
参考http://bbs.cskin.net/thread-326-1-1.html的大神的代码
socket封装
/// <summary>
/// 自定义Socket对象
/// </summary>
public class Sockets
{
/// <summary>
/// 空构造
/// </summary>
public Sockets()
{
}
/// <summary>
/// 创建Sockets对象
/// </summary>
/// <param name="ip">Ip地址</param>
/// <param name="client">TcpClient</param>
/// <param name="ns">承载客户端Socket的网络流</param>
public Sockets(IPEndPoint ip, TcpClient client, NetworkStream ns)
{
Ip = ip;
Client = client;
nStream = ns;
}
/// <summary>
/// 创建Sockets对象
/// </summary>
/// <param name="name">用户名</param>
/// <param name="pass">密码</param>
/// <param name="ip">Ip地址</param>
/// <param name="client">TcpClient</param>
/// <param name="ns">承载客户端Socket的网络流</param>
public Sockets(string name, string pass, IPEndPoint ip, TcpClient client, NetworkStream ns)
{
UserName = name;
Password = pass;
Ip = ip;
Client = client;
nStream = ns;
} /// <summary>
/// 接收缓冲区
/// </summary>
public byte[] RecBuffer = new byte[ * ];
/// <summary>
/// 发送缓冲区
/// </summary>
public byte[] SendBuffer = new byte[ * ];
/// <summary>
/// 异步接收后包的大小
/// </summary>
public int Offset { get; set; }
/// <summary>
/// 用户名
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 当前IP地址,端口号
/// </summary>
public IPEndPoint Ip { get; set; }
/// <summary>
/// 客户端主通信程序
/// </summary>
public TcpClient Client { get; set; }
/// <summary>
/// 承载客户端Socket的网络流
/// </summary>
public NetworkStream nStream { get; set; }
/// <summary>
/// 发生异常时不为null.
/// </summary>
public Exception ex { get; set; }
/// <summary>
/// 新客户端标识.如果推送器发现此标识为true,那么认为是客户端上线
/// 仅服务端有效
/// </summary>
public bool NewClientFlag { get; set; }
/// <summary>
/// 客户端退出标识.如果服务端发现此标识为true,那么认为客户端下线
/// 客户端接收此标识时,认为客户端异常.
/// </summary>
public bool ClientDispose { get; set; }
} /// <summary>
/// Socket基类(抽象类)
/// 抽象3个方法,初始化Socket(含一个构造),停止,启动方法.
/// 此抽象类为TcpServer与TcpClient的基类,前者实现后者抽象方法.
/// 作用: 纯属闲的蛋疼,不写个OO的我感觉不会写代码了...What The Fuck...
/// </summary>
public abstract class SocketObject
{
public abstract void InitSocket(IPAddress ipaddress, int port);
public abstract void InitSocket(string ipaddress, int port);
public abstract void Start();
public abstract void Stop();
}
委托传消息
public delegate void PushSockets(Sockets sockets);
服务端
/// <summary>
/// Tcp同步服务端,SocketObject继承抽象类
/// 服务端采用TcpListener封装.
/// 使用Semaphore 来控制并发,每次处理5个.最大处理5000
/// </summary>
public class TcpServer : SocketObject
{
public PushSockets pushSockets; bool IsStop = false;
object obj = new object();
/// <summary>
/// 信号量
/// </summary>
private Semaphore semap = new Semaphore(, );
/// <summary>
/// 客户端队列集合
/// </summary>
public List<Sockets> ClientList = new List<Sockets>();
/// <summary>
/// 服务端
/// </summary>
private TcpListener listener;
/// <summary>
/// 当前IP地址
/// </summary>
private IPAddress Ipaddress;
/// <summary>
/// 欢迎消息
/// </summary>
public string boundary = "";
/// <summary>
/// 当前监听端口
/// </summary>
private int Port;
/// <summary>
/// 当前IP,端口对象
/// </summary>
private IPEndPoint ip;
/// <summary>
/// 初始化服务端对象
/// </summary>
/// <param name="ipaddress">IP地址</param>
/// <param name="port">监听端口</param>
public override void InitSocket(IPAddress ipaddress, int port)
{
Ipaddress = ipaddress;
Port = port;
listener = new TcpListener(Ipaddress, Port);
}
/// <summary>
/// 初始化服务端对象
/// </summary>
/// <param name="ipaddress">IP地址</param>
/// <param name="port">监听端口</param>
public override void InitSocket(string ipaddress, int port)
{
Ipaddress = IPAddress.Parse(ipaddress);
Port = port;
ip = new IPEndPoint(Ipaddress, Port);
listener = new TcpListener(Ipaddress, Port);
}
/// <summary>
/// 启动监听,并处理连接
/// </summary>
public override void Start()
{
try
{
listener.Start();
Thread AccTh = new Thread(new ThreadStart(delegate
{
while (true)
{
if (IsStop != false)
{
break;
}
GetAcceptTcpClient();
Thread.Sleep();
}
}));
AccTh.Start();
}
catch (SocketException skex)
{
Sockets sks = new Sockets();
sks.ex = skex;
if (pushSockets != null)
pushSockets.Invoke(sks);//推送至UI
}
}
/// <summary>
/// 停止
/// </summary>
public override void Stop()
{
if (listener != null)
{
listener.Stop();
listener = null;
IsStop = true;
pushSockets = null;
}
}
/// <summary>
/// 等待处理新的连接
/// </summary>
private void GetAcceptTcpClient()
{
try
{
if (listener.Pending())
{
semap.WaitOne();
TcpClient tclient = listener.AcceptTcpClient();
//维护客户端队列
Socket socket = tclient.Client;
NetworkStream stream = new NetworkStream(socket, true); //承载这个Socket
Sockets sks = new Sockets(tclient.Client.RemoteEndPoint as IPEndPoint, tclient, stream);
sks.NewClientFlag = true;
//推送新客户端
if (pushSockets != null)
pushSockets.Invoke(sks);
//客户端异步接收
sks.nStream.BeginRead(sks.RecBuffer, , sks.RecBuffer.Length, new AsyncCallback(EndReader), sks);
//加入客户端集合.
AddClientList(sks);
//主动向客户端发送一条连接成功信息
//if (stream.CanWrite)
//{
// if (!string.IsNullOrEmpty(boundary))
// {
// byte[] buffer = Encoding.UTF8.GetBytes(boundary);
// stream.Write(buffer, 0, buffer.Length);
// }
//}
semap.Release();
}
}
catch
{
return;
}
}
/// <summary>
/// 异步接收发送的信息.
/// </summary>
/// <param name="ir"></param>
private void EndReader(IAsyncResult ir)
{
Sockets sks = ir.AsyncState as Sockets;
if (sks != null && listener != null)
{
try
{
if (sks.NewClientFlag || sks.Offset != )
{
sks.NewClientFlag = false;
sks.Offset = sks.nStream.EndRead(ir);
if (pushSockets != null)
pushSockets.Invoke(sks);//推送至UI
sks.nStream.BeginRead(sks.RecBuffer, , sks.RecBuffer.Length, new AsyncCallback(EndReader), sks);
}
}
catch (Exception skex)
{
lock (obj)
{
//移除异常类
ClientList.Remove(sks);
Sockets sk = sks;
sk.ClientDispose = true;//客户端退出
sk.ex = skex;
if (pushSockets != null)
pushSockets.Invoke(sks);//推送至UI
}
}
}
}
/// <summary>
/// 加入队列.
/// </summary>
/// <param name="sk"></param>
private void AddClientList(Sockets sk)
{
//虽然有信号量,还是用lock增加系数
lock (obj)
{
Sockets sockets = ClientList.Find(o => { return o.Ip == sk.Ip; });
//如果不存在则添加,否则更新
if (sockets == null)
{
ClientList.Add(sk);
}
else
{
ClientList.Remove(sockets);
ClientList.Add(sk);
}
}
}
/// <summary>
/// 向所有在线的客户端发送信息.
/// </summary>
/// <param name="SendData">发送的文本</param>
public void SendToAll(string SendData)
{
try
{
Parallel.ForEach(ClientList, new ParallelOptions() { MaxDegreeOfParallelism = }, item =>
{
if (item != null)
SendToClient(item.Ip, SendData);
});
}
catch (Exception ex)
{
//Console.Write(ex.Message);
}
}
/// <summary>
/// 向某一位客户端发送信息
/// </summary>
/// <param name="ip">客户端IP+端口地址</param>
/// <param name="SendData">发送的数据包</param>
public void SendToClient(IPEndPoint ip, string SendData)
{
try
{
Sockets sks = ClientList.Find(o => { return o.Ip == ip; });
if (sks == null || !sks.Client.Connected || sks.ClientDispose)
{
//没有连接时,标识退出
Sockets ks = new Sockets();
sks.ClientDispose = true;//标识客户端下线
sks.ex = new Exception("客户端无连接");
if (pushSockets != null)
pushSockets.Invoke(sks);//推送至UI
ClientList.Remove(sks);
}
if (sks.Client.Connected)
{
//获取当前流进行写入.
NetworkStream nStream = sks.nStream;
if (nStream.CanWrite)
{
byte[] buffer = Encoding.UTF8.GetBytes(SendData);
nStream.Write(buffer, , buffer.Length);
}
else
{
//避免流被关闭,重新从对象中获取流
nStream = sks.Client.GetStream();
if (nStream.CanWrite)
{
byte[] buffer = Encoding.UTF8.GetBytes(SendData);
nStream.Write(buffer, , buffer.Length);
}
else
{
//如果还是无法写入,那么认为客户端中断连接.
ClientList.Remove(sks);
Sockets ks = new Sockets();
sks.ClientDispose = true;//如果出现异常,标识客户端下线
sks.ex = new Exception("客户端无连接");
if (pushSockets != null)
pushSockets.Invoke(sks);//推送至UI }
}
}
}
catch (Exception skex)
{
Sockets sks = new Sockets();
sks.ClientDispose = true;//如果出现异常,标识客户端退出
sks.ex = skex;
if (pushSockets != null)
pushSockets.Invoke(sks);//推送至UI
}
}
}
客户端
public class TcpClients : SocketObject
{
public PushSockets pushSockets; bool IsClose = false;
/// <summary>
/// 当前管理对象
/// </summary>
Sockets sk;
/// <summary>
/// 客户端
/// </summary>
TcpClient client;
/// <summary>
/// 当前连接服务端地址
/// </summary>
IPAddress Ipaddress;
/// <summary>
/// 当前连接服务端端口号
/// </summary>
int Port;
/// <summary>
/// 服务端IP+端口
/// </summary>
IPEndPoint ip;
/// <summary>
/// 发送与接收使用的流
/// </summary>
NetworkStream nStream; /// <summary>
/// 初始化Socket
/// </summary>
/// <param name="ipaddress"></param>
/// <param name="port"></param>
public override void InitSocket(IPAddress ipaddress, int port)
{
Ipaddress = ipaddress;
Port = port;
ip = new IPEndPoint(Ipaddress, Port);
client = new TcpClient();
}
/// <summary>
/// 初始化Socket
/// </summary>
/// <param name="ipaddress">ipd地址</param>
/// <param name="port">端口</param>
public override void InitSocket(string ipaddress, int port)
{
Ipaddress = IPAddress.Parse(ipaddress);
Port = port;
ip = new IPEndPoint(Ipaddress, Port);
client = new TcpClient();
}
/// <summary>
/// 重写Start方法,其实就是连接服务端
/// </summary>
public override void Start()
{
Connect();
}
/// <summary>
/// 连接
/// </summary>
private void Connect()
{
client.Connect(ip);
nStream = new NetworkStream(client.Client, true);
sk = new Sockets(ip, client, nStream);
sk.nStream.BeginRead(sk.RecBuffer, , sk.RecBuffer.Length, new AsyncCallback(EndReader), sk);
}
/// <summary>
/// 读取
/// </summary>
private void EndReader(IAsyncResult ir)
{
Sockets s = ir.AsyncState as Sockets;
try
{
if (s != null)
{
if (IsClose && client == null)
{
sk.nStream.Close();
sk.nStream.Dispose();
return;
}
s.Offset = s.nStream.EndRead(ir);
if (pushSockets != null)
pushSockets.Invoke(s);//推送至UI
sk.nStream.BeginRead(sk.RecBuffer, , sk.RecBuffer.Length, new AsyncCallback(EndReader), sk);
}
}
catch (Exception skex)
{
Sockets sks = s;
sks.ex = skex;
sks.ClientDispose = true;
if (pushSockets != null)
pushSockets.Invoke(sks);//推送至UI
}
}
/// <summary>
/// 停止
/// </summary>
public override void Stop()
{
Sockets sks = new Sockets();
try
{
if (client != null)
{
client.Client.Shutdown(SocketShutdown.Both);
Thread.Sleep();
client.Close();
IsClose = true;
client = null;
}
else
{
sks.ex = new Exception("客户端没有初始化.!");
}
if (pushSockets != null)
pushSockets.Invoke(sks);//推送至UI
}
catch (Exception ex)
{
sks.ex = ex;
}
}
/// <summary>
/// 发送消息
/// </summary>
public void SendData(string SendData)
{
try
{
if (client == null || !client.Connected)
{
Sockets sks = new Sockets();
sks.ex = new Exception("客户端无连接..");
sks.ClientDispose = true;
if (pushSockets != null)
pushSockets.Invoke(sks);//推送至UI
}
if (client.Connected) //如果连接则发送
{
if (nStream == null)
{
nStream = client.GetStream();
}
byte[] buffer = Encoding.UTF8.GetBytes(SendData);
nStream.Write(buffer, , buffer.Length);
}
}
catch (Exception skex)
{
Sockets sks = new Sockets();
sks.ex = skex;
sks.ClientDispose = true;
if (pushSockets != null)
pushSockets.Invoke(sks);//推送至UI
}
}
}
加密消息的类
/// <summary>
/// 数据DES加密
/// </summary>
public class Encrypt
{
private byte[] iba_mIV = new byte[]; //向量
private byte[] iba_mKey = new byte[]; //密钥
private DESCryptoServiceProvider io_DES = new DESCryptoServiceProvider(); public Encrypt()
{
this.iba_mKey[] = 0x95;
this.iba_mKey[] = 0xc4;
this.iba_mKey[] = 0xf6;
this.iba_mKey[] = 0x49;
this.iba_mKey[] = 0xac;
this.iba_mKey[] = 0x61;
this.iba_mKey[] = 0xa3;
this.iba_mKey[] = 0xe2;
this.iba_mIV[] = 0xf9;
this.iba_mIV[] = 0x6a;
this.iba_mIV[] = 0x65;
this.iba_mIV[] = 0xb8;
this.iba_mIV[] = 0x4a;
this.iba_mIV[] = 0x23;
this.iba_mIV[] = 0xfe;
this.iba_mIV[] = 0xc6;
this.io_DES.Key = this.iba_mKey;
this.io_DES.IV = this.iba_mIV;
}
/// <summary>
/// 初始化加密向量与密钥 长度为8
/// </summary>
/// <param name="iba_mIV">向量</param>
/// <param name="iba_mKey">密钥</param>
public Encrypt(byte[] iba_mIV, byte[] iba_mKey)
{
this.io_DES.IV = iba_mIV;
this.io_DES.Key = iba_mKey;
}
/// <summary>
/// 解密
/// </summary>
/// <param name="as_Data"></param>
/// <returns></returns>
public string doDecrypt(string as_Data)
{
ICryptoTransform lo_ICT = this.io_DES.CreateDecryptor(this.io_DES.Key, this.io_DES.IV);
try
{
byte[] lba_bufIn = this.FromHexString(as_Data);//Encoding.UTF8.GetString(Convert.FromBase64String(
byte[] lba_bufOut = lo_ICT.TransformFinalBlock(lba_bufIn, , lba_bufIn.Length);
return Encoding.UTF8.GetString(lba_bufOut);
}
catch
{
return as_Data;
}
}
/// <summary>
/// 加密
/// </summary>
/// <param name="as_Data"></param>
/// <returns></returns>
public string doEncrypt(string as_Data)
{
ICryptoTransform lo_ICT = this.io_DES.CreateEncryptor(this.io_DES.Key, this.io_DES.IV);
try
{
byte[] lba_bufIn = Encoding.UTF8.GetBytes(as_Data);
byte[] lba_bufOut = lo_ICT.TransformFinalBlock(lba_bufIn, , lba_bufIn.Length);
return GetHexString(lba_bufOut);//Convert.ToBase64String(Encoding.UTF8.GetBytes();
}
catch
{
return "";
}
}
/// <summary>
/// 转换2进制
/// </summary>
/// <param name="as_value"></param>
/// <returns></returns>
private byte[] FromHexString(string as_value)
{
byte[] lba_buf = new byte[Convert.ToInt32((int)(as_value.Length / ))];
for (int li_i = ; li_i < lba_buf.Length; li_i++)
{
lba_buf[li_i] = Convert.ToByte(as_value.Substring(li_i * , ), 0x10);
}
return lba_buf;
}
/// <summary>
/// 字节转字符串
/// </summary>
/// <param name="aba_buf"></param>
/// <returns></returns>
private string GetHexString(byte[] aba_buf)
{
StringBuilder lsb_value = new StringBuilder();
foreach (byte lb_byte in aba_buf)
{
lsb_value.Append(Convert.ToString(lb_byte, 0x10).PadLeft(, ''));
}
return lsb_value.ToString();
}
}
cs端控件刷新
public class ControlInvoker
{
public static void Invoke(Control ctl, ThreadStart thread)
{
try
{
if (!ctl.IsHandleCreated)
return; if (ctl.IsDisposed)
return; if (ctl.InvokeRequired)
{
ctl.Invoke(thread);
}
else
{
thread();
}
}
catch (Exception ex)
{
Console.Write(ex);
}
}
}
服务端构建
private TcpServer _server; private void frmSocketServer_Load(object sender, EventArgs e)
{
_server = new TcpServer();
_server.pushSockets = Rec;
} /// <summary>
/// 委托刷新客户数据
/// </summary>
private void Rec(Sockets sks)
{
ControlInvoker.Invoke(this, new ThreadStart(delegate
{
//这个是存放消息的,不用管
if (txtClientState.Lines.Count() > )
{
string path = HandleTxt.CreateFile(AppDomain.CurrentDomain.BaseDirectory + @"log\", DateTime.Now);//创造路径
HandleTxt.WriteTxt(path + @"\" + DateTime.Now.ToString("HHmmss") + ".txt", txtClientState.Lines.ToList());
txtClientState.Text = "";
}
if (sks.ex != null)
{
//在此处理异常信息
if (sks.ClientDispose)
{
//客户端非主动断开连接下线. 非正常下线
if (sks.Ip != null)
{
RemoveClient(sks, string.Format("客户端:{0}下线.{1}!\r\n", sks.Ip, sks.ex.Message));
}
}
}
else
{
if (sks.NewClientFlag)
{
AddClient(sks, string.Format("新客户端:{0}连接成功.!\r\n", sks.Ip));
}
else if (sks.Offset == )
{
//正常是不会发送0包的,只有客户端主动断开连接时发送空包.
//客户端下线.
RemoveClient(sks, string.Format("客户端:{0}下线.!\r\n", sks.Ip));
}
else
{
//这里是界面提示消息
//sks
}
}
}));
} /// <summary>
/// 接收客户端消息
/// </summary>
private void ClientInfo(Sockets sks)
{
byte[] buffer = new byte[sks.Offset];
Array.Copy(sks.RecBuffer, buffer, sks.Offset);
string str = Encoding.UTF8.GetString(buffer); } /// <summary>
/// 启动服务
/// </summary>
private void StartServer()
{
try
{
_server.InitSocket(IPAddress.Any, );
_server.Start();
// ClientState("服务端启动成功.!\r\n");
// SetEnabled(false);
}
catch (Exception ex)
{
//ClientState(string.Format("启动失败!原因:{0}", ex.Message));
// SetEnabled(true);
}
} /// <summary>
/// 发送消息给客户端
/// </summary>
private void SendToClient(IPEndPoint ip, string SendData)
{
Task.Factory.StartNew(new Action(() =>
{
Thread.Sleep();
_server.SendToClient(ip, SendData);
}));
}
/// <summary>
/// 推送消息
/// </summary>
private void SendMess()
{
Task.Factory.StartNew(new Action(() =>
{
_server.SendToAll("");
}));
}
客户端接收及发送
private TcpClients _client;
private void frmPlaySingleInfo_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
_client = new TcpClients();
_client.pushSockets = ReceiveMess;//注册推送器
} /// <summary>
/// 处理推送过来的消息
/// </summary>
/// <param name="rec"></param>
private void ReceiveMess(Sockets sks)
{
ControlInvoker.Invoke(this, new ThreadStart(delegate
{
if (sks.ex != null)
{
if (sks.ClientDispose == true)
{
//由于未知原因引发异常.导致客户端下线. 比如网络故障.或服务器断开连接.
//SetClientState(string.Format("客户端下线.!异常消息:{0}\r\n", sks.ex));
}
else
{
//SetClientState(string.Format("异常消息:{0}\r\n", sks.ex));
}
//timerConnect.Enabled = true;
}
else if (sks.Offset == )
{
//客户端主动下线
// SetClientState("客户端下线.!");
}
else
{
byte[] buffer = new byte[sks.Offset];
Array.Copy(sks.RecBuffer, buffer, sks.Offset);
string str = Encoding.UTF8.GetString(buffer);
if (sks.Client.Client.Available > )//判断消息是否发送完成,socket的数据大小限制,分多个包发送
{
Console.Write(str);
_mess += str;
}
else
{
_mess += str;
//接收完成消息后处理 。。。
_mess = "";
}
}
}));
} /// <summary>
/// 解析域名
/// </summary>
private string DomainName(string strDomain)
{
IPHostEntry host = Dns.GetHostByName(strDomain);
IPAddress ip = host.AddressList[];
return ip.ToString();
} /// <summary>
/// 设置端口等数据
/// 是否重连
/// </summary>
private void SetData(PlaySingleXml model, bool isConn)
{
_ip = ExistIp(model.ip);
_port = model.port;
timer.Interval = model.minutes * * ;
if (isConn)
ConnectSocket();
}
/// <summary>
/// 验证ip地址是否是连接
/// </summary>
private string ExistIp(string ip)
{
Match m = Regex.Match(ip, @"((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))"); // 匹配正则表达式
if (!m.Success)
{
return DomainName(ip);
}
else
{
return ip;
}
} /// <summary>
/// 连接Socket
/// </summary>
private void ConnectSocket()
{
try
{
_client.InitSocket(_ip, _port);
_client.Start();
//SetClientState("连接成功.!");
//timerConnect.Enabled = false;
}
catch (Exception ex)
{
//SetClientState(ex.Message);
//timerConnect.Enabled = true;
}
}
这个socket通讯基本完成
最后再附上另一个大神的东西http://bbs.cskin.net/thread-874-1-1.html
c#Socket通讯的更多相关文章
- 闲来无事,写个基于TCP协议的Socket通讯Demo
.Net Socket通讯可以使用Socket类,也可以使用 TcpClient. TcpListener 和 UdpClient类.我这里使用的是Socket类,Tcp协议. 程序很简单,一个命令行 ...
- 试解析Tomcat运行原理(一)--- socket通讯
关于这篇文章也确实筹划了很久,今天决定开篇写第一篇,说起tomcat首先很容易联想到IIS,因为我最开始使用的就是.net技术,我第一次使用asp写学生成绩管理系统后,很茫然如何让别人都能看到或者说使 ...
- c# TCP Socket通讯基础
在做网络通讯方面的程序时,必不可少的是Socket通讯. 那么我们需要有一套既定的,简易的通讯流程. 如下: <pre name="code" class="csh ...
- Android笔记:Socket通讯常见问题
经验证的socket通讯问题 1.如果是模拟器和本机PC直接通讯,需要使用本机IP地址 而不是 10.0.2.2 如本机的静态地址为192.168.1.2 则直接使用该地址 2.接收和连接代码不能在 ...
- java socket通讯(二)处理多个客户端连接
通过java socket通讯(一) 入门示例,就可以实现服务端和客户端的socket通讯,但是上一个例子只能实现一个服务端和一个客户端之间的通讯,如果有多个客户端连接服务端,则需要通过多线程技术来实 ...
- java socket通讯(一) 入门示例
一.入门 要想学习socket通讯,首先得知道tcp/ip和udp连接,具体可参考浅谈TCP/IP 和 UDP的区别 二.示例 首先新建了一个java工程,包括两个部分,客户端SocketClient ...
- Socket网络通讯开发总结之:Java 与 C进行Socket通讯 + [备忘] Java和C之间的通讯
Socket网络通讯开发总结之:Java 与 C进行Socket通讯 http://blog.sina.com.cn/s/blog_55934df80100i55l.html (2010-04-08 ...
- 利用BlazeDS的AMF3数据封装与Flash 进行Socket通讯
前几天看到了Adobe有个开源项目BlazeDS,里面提供了Java封装AMF3格式的方法.这个项目貌似主要是利用Flex来Remoting的,不过我们可以利用他来与Flash中的Socket通讯. ...
- .Net中的Socket通讯
.NetFrameWork为Socket通讯提供了System.Net.Socket命名空间,在这个命名空间里面有以下几个常用的重要类分别是: ·Socket类 这个低层的类用于管理连接,WebReq ...
- Linux网络服务器epoll模型的socket通讯的实现(一)
准备写一个网络游戏的服务器的通讯模块,参考网上看到的一些代码,在linux下面实现一个多线程的epoll模型的socket通讯的代码,以下是第一部分多线程的切换代码: 1 #include <s ...
随机推荐
- SOA(面向服务的架构)初识
SOA是一种设计方法,其中包含多个服务,而服务之间通过配合最终会提供一系列功能.一个服务通常以独立的方式存在于操作系统中.服务之间通过网络调用(常见有http+xml.http+json等),而非进程 ...
- 在testrpc以太坊测试环境部署智能合约
2018年03月13日 09:20:54 思无邪-machengyu 阅读数 2683 版权声明:本文为博主原创文章,转载请务必注明出处,否则追究法律责任 https://blog.csdn.ne ...
- Build Telemetry for Distributed Services之OpenTracing指导:C#
官网链接:https://opentracing.io/guides/ 官方微博:https://medium.com/opentracing Welcome to the OpenTracing G ...
- git clone https://chromium.googlesource.com/失败
一.现象 连接着vpn,网页上可以直接打开网站,但是使用terminal 执行git clone https://chromium.googlesource.com/xxxx时, 报错 ...
- UICollectionview的头视图和尾视图
UITableView有头视图和尾视图,那么UICollectionView有没有头视图和尾视图呢? 答案是有的. 1.新建一个类,必须继承自 UICollectionReusableView. 2. ...
- jenkins通过ssh登不上远程主机
https://blog.csdn.net/cdnight/article/details/81078191 就是需要切换jenkins用户,用jenkins用户生产的秘钥拷到其他主机上
- iOS-static和const联合使用;使用static const 与 #define
static和const联合使用: static将一个全局变量变成局部变量 const将一个局部变量变成局部常量 // 定义了一个局部常量 static const CGFloat ...
- [MSCOCO] Ubuntu16.04下使用 tylin/coco-caption 评价 MSCOCO Caption(配置,及Demo运行)
Github链接:https://github.com/tylin/coco-caption Ubuntu版本信息 Linux内核版本号:Linux version 4.15.0-51-generic ...
- Go语言中defer语句使用小结
defer是Go语言中的延迟执行语句,用来添加函数结束时执行的代码,常用于释放某些已分配的资源.关闭数据库连接.断开socket连接.解锁一个加锁的资源.Go语言机制担保一定会执行defer语句中的代 ...
- CG-CTF 南邮 综合题2
个人网站 http://www.wjlshare.tk 0x00前言 主要考了三块 第一块是文件包含获取源码 第二块是通过sql绕过注入获取密码 第三块是三参数回调后门的利用 做这题的时候结合了别人的 ...