ConsoleWebsocketServer服务端和ConsoleWebsocketClient客户端
本文是简述了Websocket的服务端和客户端的实时通讯过程,Websocket的服务端和客户端的具体使用使用了2种Websocket的服务端和2种客户端。
以下代码使用的是Visual Studio 2019 Enterprise版本,控制台项目使用的是 .NETFramework,Version=v4.7.2,同时为了调试方便,做了log4net日志处理,log4net日志的使用可以百度
Websocket服务端
1、新建项目ConsoleWebsocketServer
2、项目右键 管理Nuget程序包,,搜索 SuperWebSocketNETServer,添加即可
3、新建文件夹ServerEntities,然后再该文件夹下添加HttpAndWebsocket和ConsoleAppWebsocketServer这两个类,代码如下
HttpAndWebsocket类
using System;
using System.Net;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleWebsocketServer.ServerEntities
{
public class HttpAndWebsocket
{
public async void Start(string url)
{
string url1 = "http://+:80/";
int Port = 1234;
HttpListener httpListener = new HttpListener();
httpListener.Prefixes.Add("http://+:" + Port + "/");
httpListener.Start();
while (true)
{
try
{
HttpListenerContext httpListenerContext = await httpListener.GetContextAsync();
try
{
if (httpListenerContext.Request.IsWebSocketRequest)
{
ProcessRequest(httpListenerContext);
}
}
catch (Exception)
{
httpListenerContext.Response.StatusCode = 400;
httpListenerContext.Response.Close();
}
}
catch (Exception)
{
throw;
}
}
}
private async void ProcessRequest(HttpListenerContext listenerContext)
{
HttpListenerWebSocketContext httpListenerWebSocket;
try
{
httpListenerWebSocket = await listenerContext.AcceptWebSocketAsync(null);
}
catch (Exception)
{
listenerContext.Response.StatusCode = 500;
listenerContext.Response.Close();
return;
}
WebSocket webSocket = httpListenerWebSocket.WebSocket;
try
{
while (webSocket.State == WebSocketState.Open)
{
byte[] returnBytes = new byte[10240];
WebSocketReceiveResult webSocketReceiveResult = await webSocket.ReceiveAsync(new ArraySegment<byte>(returnBytes), CancellationToken.None);
string ReceivesData = Encoding.UTF8.GetString(returnBytes, 0, webSocketReceiveResult.Count);
ReceivesData = $"我已经收到数据:{ReceivesData}";
returnBytes = Encoding.UTF8.GetBytes(ReceivesData);
await webSocket.SendAsync(new ArraySegment<byte>(returnBytes), WebSocketMessageType.Text, true, CancellationToken.None);
await Task.Delay(TimeSpan.FromSeconds(3));
}
}
catch (Exception)
{
throw;
}
finally
{
if (webSocket != null)
{
webSocket.Dispose();
}
}
}
}
}
ConsoleAppWebsocketServer类
using SuperWebSocket;
using System;
using System.Web;
namespace ConsoleWebsocketServer.ServerEntities
{
/// <summary>
/// SuperWebSocket服务端
/// </summary>
public class ConsoleAppWebsocketServer
{
public static WebSocketServer ws = null;
public void Start()
{
ws = new WebSocketServer();
ws.NewSessionConnected += Ws_NewSessionConnected;
ws.NewMessageReceived += Ws_NewMessageReceived;
ws.SessionClosed += Ws_SessionClosed;
if (!ws.Setup("127.0.0.1", 1234))
{
Console.WriteLine("ChatWebSocket 设置WebSocket服务侦听地址失败");
return;
}
if (!ws.Start())
{
Console.WriteLine("ChatWebSocket 启动WebSocket服务侦听失败");
return;
}
while (true)
{
}
}
public void Ws_NewSessionConnected(WebSocketSession session)
{
Console.WriteLine("{0:HH:MM:ss} 与客户端:{1}创建新会话", DateTime.Now, GetSessionName(session));
var msg = string.Format("{0:HH:MM:ss} {1} 进入聊天室", DateTime.Now, GetSessionName(session));
SendToAll(session, msg);
}
private void Ws_NewMessageReceived(WebSocketSession session, string value)
{
var msg = string.Format("{0:HH:MM:ss} {1} 说: {2}", DateTime.Now, GetSessionName(session), value);
Console.WriteLine($"{msg}");
SendToAll(session, msg);
}
public void Ws_SessionClosed(WebSocketSession session, SuperSocket.SocketBase.CloseReason value)
{
Console.WriteLine("{0:HH:MM:ss} 与客户端:{1}的会话被关闭 原因:{2}", DateTime.Now, GetSessionName(session), value);
var msg = string.Format("{0:HH:MM:ss} {1} 离开聊天室", DateTime.Now, GetSessionName(session));
SendToAll(session, msg);
}
/// <summary>
/// 启动服务
/// </summary>
/// <returns></returns>
public void StartWebsocket()
{
if (!ws.Setup("127.0.0.1", 1234))
{
Console.WriteLine("ChatWebSocket 设置WebSocket服务侦听地址失败");
return;
}
if (!ws.Start())
{
Console.WriteLine("ChatWebSocket 启动WebSocket服务侦听失败");
return;
}
Console.WriteLine("ChatWebSocket 启动服务成功");
}
/// <summary>
/// 停止侦听服务
/// </summary>
public void Stop()
{
if (ws != null)
{
ws.Stop();
}
}
public string GetSessionName(WebSocketSession session)
{
return HttpUtility.UrlDecode(session.Path.TrimStart('/'));
}
public void SendToAll(WebSocketSession session, string msg)
{
foreach (var sendSession in session.AppServer.GetAllSessions())
{
sendSession.Send(msg);
}
}
}
}
4、ConsoleWebsocketServer的Program.cs 代码如下
using ConsoleWebsocketServer.ServerEntities;
using SuperWebSocket;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace ConsoleWebsocketServer
{
class Program
{
public static WebSocketServer ws = null;
static void Main(string[] args)
{
#region 启动http服务接受websocket请求
Console.WriteLine("启动http服务的WebSocket服务");
HttpAndWebsocket httpAndWebsocket = new HttpAndWebsocket();
httpAndWebsocket.Start("ws://127.0.0.1:1234");
Console.WriteLine("ChatWebSocket 启动服务成功");
Console.WriteLine("按 Enter 退出...");
Console.ReadKey();
#endregion
#region 启动websocket服务接受websocket请求
//Console.WriteLine("WebSocket服务");
//ws = new WebSocketServer();
//ws.NewSessionConnected += Ws_NewSessionConnected;
//ws.NewMessageReceived += Ws_NewMessageReceived;
//ws.SessionClosed += Ws_SessionClosed;
//if (!ws.Setup("127.0.0.1", 1234))
//{
// Console.WriteLine("ChatWebSocket 设置WebSocket服务侦听地址失败");
// return;
//}
//if (!ws.Start())
//{
// Console.WriteLine("ChatWebSocket 启动WebSocket服务侦听失败");
// return;
//}
//Console.WriteLine("ChatWebSocket 启动服务成功");
//Console.WriteLine("按 Enter 推出...");
//Console.ReadKey();
//ws.Stop();
#endregion
}
public static void Ws_NewSessionConnected(WebSocketSession session)
{
Console.WriteLine("{0:HH:MM:ss} 与客户端:{1}创建新会话", DateTime.Now, GetSessionName(session));
var msg = string.Format("{0:HH:MM:ss} {1} 进入聊天室", DateTime.Now, GetSessionName(session));
SendToAll(session, msg);
}
private static void Ws_NewMessageReceived(WebSocketSession session, string value)
{
var msg = string.Format("{0:HH:MM:ss} {1} 说: {2}", DateTime.Now, GetSessionName(session), value);
Console.WriteLine($"{msg}");
SendToAll(session, msg);
}
public static void Ws_SessionClosed(WebSocketSession session, SuperSocket.SocketBase.CloseReason value)
{
Console.WriteLine("{0:HH:MM:ss} 与客户端:{1}的会话被关闭 原因:{2}", DateTime.Now, GetSessionName(session), value);
var msg = string.Format("{0:HH:MM:ss} {1} 离开聊天室", DateTime.Now, GetSessionName(session));
SendToAll(session, msg);
}
/// <summary>
/// 启动服务
/// </summary>
/// <returns></returns>
public static void Start()
{
if (!ws.Setup("127.0.0.1", 1234))
{
Console.WriteLine("ChatWebSocket 设置WebSocket服务侦听地址失败");
return;
}
if (!ws.Start())
{
Console.WriteLine("ChatWebSocket 启动WebSocket服务侦听失败");
return;
}
Console.WriteLine("ChatWebSocket 启动服务成功");
}
/// <summary>
/// 停止侦听服务
/// </summary>
public static void Stop()
{
if (ws != null)
{
ws.Stop();
}
}
public static string GetSessionName(WebSocketSession session)
{
return HttpUtility.UrlDecode(session.Path.TrimStart('/'));
}
public static void SendToAll(WebSocketSession session, string msg)
{
foreach (var sendSession in session.AppServer.GetAllSessions())
{
sendSession.Send(msg);
}
}
}
}
Websocket客户端
1、新建项目ConsoleWebsocketClient
2、项目右键 管理Nuget程序包,,搜索 log4net,WebSocket4NET,添加即可
3、新建文件夹ClientEntities,然后再该文件夹下添加ClientWebsocketEntity和ConsoleAppWebsocketClient这两个类,代码如下
ClientWebsocketEntity类
using ConsoleWebsocketClient.CommonUntils;
using System;
using System.IO;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleWebsocketClient.ClientEntities
{
/// <summary>
/// ClientWebsocket客户端实体类
/// </summary>
public class ClientWebsocketEntity
{
#region Fields And Propertities
/// <summary>
/// ClientWebsocket客户端Url
/// </summary>
public string SocketUrl { get; set; } = "ws://127.0.0.1:1234/";
//public string SocketUrl { get; set; } = "ws://192.168.1.198:1234/";
/// <summary>
/// ClientWebsocket客户端对象
/// </summary>
public ClientWebSocket ClientWebSocket { get; set; }
/// <summary>
/// 消息回传的委托定义
/// </summary>
/// <param name="retValue"></param>
public delegate void ShowMessage(string retValue);
/// <summary>
/// 消息回传
/// </summary>
public ShowMessage ReturnMessage;
#endregion
#region Methods
/// <summary>
/// 构造函数初始化
/// </summary>
public ClientWebsocketEntity()
{
ClientWebSocket = new ClientWebSocket();
//ClientWebsocketConnect();
}
public void StartClient()
{
ClientWebsocketConnect();
}
/// <summary>
/// ClientWebsocket客户端连接Websocket服务端
/// </summary>
public async void ClientWebsocketConnect()
{
try
{
await ClientWebSocket.ConnectAsync(new Uri(SocketUrl), CancellationToken.None);
ClientWebsocketSendMessage();
ClientWebsocketReceivedMessage();
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// ClientWebsocket客户端向Websocket服务端发送消息
/// </summary>
public async void ClientWebsocketSendMessage()
{
try
{
while (true)
{
byte[] bytess = Encoding.Default.GetBytes($"login#22222");
await ClientWebSocket.SendAsync(new ArraySegment<byte>(bytess), WebSocketMessageType.Text, true, new CancellationToken());
await Task.Delay(1000 * 3);
}
//while (ClientWebSocket.State == WebSocketState.Open)
//{
// byte[] buffer = new byte[10240];
// await ClientWebSocket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Text, true, CancellationToken.None);
// await Task.Delay(TimeSpan.FromSeconds(3));
//}
}
catch (Exception ex)
{
LogHelper.Instance.Error($"{ex.Message}");
throw;
}
}
/// <summary>
/// ClientWebsocket客户端从Websocket服务端接收消息
/// </summary>
public async void ClientWebsocketReceivedMessage()
{
try
{
//while (true)
//{
// //byte[] bytess = Encoding.Default.GetBytes($"TestWebsocket发送数据 {s} ");
// //cln.SendAsync(new ArraySegment<byte>(bytess), WebSocketMessageType.Text, true, new CancellationToken()).Wait();
// //s++;
// string returnValue = await GetAsyncValue(ClientWebSocket);//异步方法
// ReturnMessage?.Invoke(returnValue);
//}
while (ClientWebSocket.State == WebSocketState.Open)
{
ArraySegment<byte> buffer = new ArraySegment<byte>(new byte[1024 * 4]);
WebSocketReceiveResult result = await ClientWebSocket.ReceiveAsync(buffer, CancellationToken.None);
if (result.EndOfMessage)
{
if (result.MessageType == WebSocketMessageType.Text)
{
//string retValue = Encoding.UTF8.GetString(buffer.Array).Replace("\0", "").Trim(); // Encoding.UTF8.GetString(buffer.Array)会多出很多空余的字符,添加Replace("\0", "").Trim()处理掉就可以了
string retValue = Encoding.UTF8.GetString(buffer.Array, 0, result.Count);
ReturnMessage?.Invoke(retValue);
}
}
}
//WebSocketReceiveResult result;
//ArraySegment<byte> buffer;
//string retValue;
//while (ClientWebSocket.State == WebSocketState.Open)
//{
// using (var ms = new MemoryStream())
// {
// buffer = new ArraySegment<byte>(new byte[1024]);
// do
// {
// result = await ClientWebSocket.ReceiveAsync(buffer, CancellationToken.None);
// ms.Write(buffer.Array, buffer.Offset, result.Count);
// }
// while (!result.EndOfMessage);
// ms.Seek(0, SeekOrigin.Begin);
// if (result.MessageType == WebSocketMessageType.Text)
// {
// using (var reader = new StreamReader(ms, Encoding.UTF8))
// {
// retValue = reader.ReadToEnd();
// ReturnMessage?.Invoke(retValue);
// }
// }
// }
//}
}
catch (Exception ex) when (!string.IsNullOrEmpty(ex.Message))
{
LogHelper.Instance.Error($"{ex.Message}");
throw;
}
}
public static async Task<string> GetAsyncValue(ClientWebSocket clientWebSocket)
{
string returnValue = null;
ArraySegment<Byte> buffer = new ArraySegment<byte>(new Byte[8192]);
WebSocketReceiveResult result = null;
using (var ms = new MemoryStream())
{
do
{
result = await clientWebSocket.ReceiveAsync(buffer, CancellationToken.None);
ms.Write(buffer.Array, buffer.Offset, result.Count);
}
while (!result.EndOfMessage);
ms.Seek(0, SeekOrigin.Begin);
if (result.MessageType == WebSocketMessageType.Text)
{
using (var reader = new StreamReader(ms, Encoding.UTF8))
{
returnValue = reader.ReadToEnd();
//Console.WriteLine(returnValue);
}
}
}
return returnValue;
}
#endregion
}
}
ConsoleAppWebsocketClient类
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace ConsoleWebsocketClient.ClientEntities
{
class ConsoleAppWebsocketClient
{
static WebSocket4Net.WebSocket webSocket4NetFaceValidate = null;
static void Start(string[] args)
{
Console.WriteLine("WebSocket客户端");
Thread.Sleep(TimeSpan.FromSeconds(8));
webSocket4NetFaceValidate = new WebSocket4Net.WebSocket("ws://127.0.0.1:1234");
webSocket4NetFaceValidate.Opened += WebSocket4NetFaceValidate_Opened;
webSocket4NetFaceValidate.MessageReceived += WebSocket4NetFaceValidate_MessageReceived;
webSocket4NetFaceValidate.Error += WebSocket4NetFaceValidate_Error;
webSocket4NetFaceValidate.Open();
//WebSocketSendmessage();
//Thread thread = new Thread(WebSocketSendmessage);
//thread.IsBackground = true;
//thread.Start();
Console.ReadKey();
}
private static void WebSocket4NetFaceValidate_Error(object sender, SuperSocket.ClientEngine.ErrorEventArgs e)
{
throw new NotImplementedException();
}
public static void WebSocketSendmessage()
{
int s = 88;
while (true)
{
webSocket4NetFaceValidate.Send(s.ToString());
s++;
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));
}
Console.WriteLine($"begin#123456");
byte[] bytess = Encoding.Default.GetBytes($"begin#123456");
IList<ArraySegment<byte>> list = new List<ArraySegment<byte>>();
list.Add(new ArraySegment<byte>(bytess));
webSocket4NetFaceValidate.Send(list);
}
private static void WebSocket4NetFaceValidate_Opened(object sender, EventArgs e)
{
Console.WriteLine($"begin#123456");
byte[] bytess = Encoding.Default.GetBytes($"begin#123456");
IList<ArraySegment<byte>> list = new List<ArraySegment<byte>>();
list.Add(new ArraySegment<byte>(bytess));
webSocket4NetFaceValidate.Send(list);
}
private static void WebSocket4NetFaceValidate_MessageReceived(object sender, WebSocket4Net.MessageReceivedEventArgs e)
{
try
{
string returnMessage = e.Message;
if (string.IsNullOrEmpty(returnMessage))
{
return;
}
Console.WriteLine(returnMessage);
}
catch (Exception ex)
{
}
finally
{
}
}
}
}
4、ConsoleWebsocketClient的Program.cs 代码如下
using ConsoleWebsocketClient.ClientEntities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleWebsocketClient
{
class Program
{
static WebSocket4Net.WebSocket webSocket4Net = null;
static void Main(string[] args)
{
#region ClientWebsocke客户端
//Thread.Sleep(TimeSpan.FromSeconds(3));
Console.WriteLine("WebSocket客户端");
for (int i = 0; i < 1; i++)
{
//System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
//System.Threading.Tasks.Task.Factory.StartNew(BBB, i);
//Task.Delay(2000);
ClientWebsocketEntity clientWebsocketEntity = new ClientWebsocketEntity();
clientWebsocketEntity.ReturnMessage = Addlog;
clientWebsocketEntity.StartClient();
}
Console.ReadKey();
#endregion
#region WebSocket4Net客户端
//Console.WriteLine("WebSocket客户端");
//webSocket4Net = new WebSocket4Net.WebSocket("ws://127.0.0.1:1234");
//webSocket4Net.Opened += WebSocket4Net_Opened;
//webSocket4Net.MessageReceived += WebSocket4Net_MessageReceived;
//webSocket4Net.Error += WebSocket4Net_Error;
//webSocket4Net.Open();
////WebSocketSendmessage();
//Thread thread = new Thread(WebSocketSendmessage);
//thread.IsBackground = true;
//thread.Start();
//Console.ReadKey();
#endregion
}
public static void Addlog(string sss)
{
Console.WriteLine(sss);
}
public static void WebSocketSendmessage()
{
int s = 88;
while (true)
{
webSocket4Net.Send(s.ToString());
s++;
Thread.Sleep(TimeSpan.FromSeconds(3));
}
}
private static void WebSocket4Net_Error(object sender, SuperSocket.ClientEngine.ErrorEventArgs e)
{
//throw new NotImplementedException();
}
private static void WebSocket4Net_Opened(object sender, EventArgs e)
{
Console.WriteLine($"begin#123456");
byte[] bytess = Encoding.Default.GetBytes($"begin#123456");
IList<ArraySegment<byte>> list = new List<ArraySegment<byte>>();
list.Add(new ArraySegment<byte>(bytess));
webSocket4Net.Send(list);
}
private static void WebSocket4Net_MessageReceived(object sender, WebSocket4Net.MessageReceivedEventArgs e)
{
try
{
string returnMessage = e.Message;
if (string.IsNullOrEmpty(returnMessage))
{
return;
}
Console.WriteLine(returnMessage);
}
catch (Exception ex)
{
}
finally
{
}
}
}
}
5、ConsoleWebsocketClient的App.config 代码如下
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\Log.txt" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="100" />
<param name="MaximumFileSize" value="2MB" />
<param name="RollingStyle" value="Size" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-15p %d [%c] %m %n" />
</layout>
</appender>
<root>
<level value="all" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
5、为了测试方便添加了HTML文件websockettest.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="https://www.baidu.com" />
<title>websocket test</title>
<script>
var socket;
function Connect(){
try{
socket=new WebSocket('ws://127.0.0.1:1234');
}catch(e){
alert('error');
return;
}
socket.onopen = sOpen;
socket.onerror = sError;
socket.onmessage= sMessage;
socket.onclose= sClose;
}
function sOpen(){
alert('connect success!');
}
function sError(e){
alert("error " + e);
}
function sMessage(msg){
document.getElementById("msgrecv").value = msg.data;
}
function sClose(e){
alert("connect closed:" + e.code);
}
function Send(){
socket.send(document.getElementById("msg").value);
}
function Close(){
socket.close();
}
</script>
</head>
<body>
<input id="msg" type="text" size = "200" >
<input id="msgrecv" type="text" size = "200">
<button id="connect" onclick="Connect();">Connect</button>
<button id="send" onclick="Send();">Send</button>
<button id="close" onclick="Close();">Close</button>
</body>
</html>
以上ConsoleWebsocketServer项目和ConsoleWebsocketClient项目都建好了,就可以运行了,其中可以设置两种Websocket服务端和Websocket客户端(websockettest.html网页端,也是客户端)
服务端
客户端
运行结果
ConsoleWebsocketServer服务端和ConsoleWebsocketClient客户端的更多相关文章
- [发布]SuperIO v2.2.5 集成OPC服务端和OPC客户端
SuperIO 下载:本站下载 百度网盘 1.修复串口号大于等于10的时候导致IO未知状态. 2.优化RunIODevice(io)函数内部处理流程,二次开发可以重载这个接口. 3.优化IO接收数据, ...
- SVN--下载、安装VisualSVN server 服务端和 TortoiseSVN客户端
前言: 在http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html的博客中已经很详细地介绍了SVN的服务器--VisualS ...
- “快的打车”创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - V2EX
"快的打车"创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - ...
- 使用rsync在windows(服务端)与linux(客户端)之间同步
说明: 1.cwRsyncServer服务端 系统:Windows7 IP地址:192.168.0.110 2.Rsync客户端 系统:CentOS 6.7 IP地址:192.168.0.141 实现 ...
- Spring Cloud 服务端注册与客户端调用
Spring Cloud 服务端注册与客户端调用 上一篇中,我们已经把Spring Cloud的服务注册中心Eureka搭建起来了,这一章,我们讲解如何将服务注册到Eureka,以及客户端如何调用服务 ...
- centos 6.5环境利用iscsi搭建SAN网络存储服务及服务端target和客户端initiator配置详解
一.简介 iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的.可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够 ...
- Delphi XE5通过WebService开发Web服务端和手机客户端
Delphi XE5通过WebService开发Web服务端和手机客户端介绍 我们开发一个三层的android程序 建立一个webservices stand-alone vcl applicati ...
- java网络编程TCP传输—流操作—服务端反馈与客户端接收
在读取完流后,服务端会向客户端返回一些数据,告诉客户端,已经写完了. 在这里和”流操作—拿到源后的写入动作“差不多,客户端同样以byte与Buffered两种缓冲读取作为例子,同时,.也是希望大家给补 ...
- 基于TCP协议套接字,服务端实现接收客户端的连接并发
基于TCP协议套接字,服务端实现接收客户端的连接并发 服务端 import socket from multiprocessing import Process server=socket.socke ...
随机推荐
- centos7 安装 git服务器
服务器端配置 yum install -y git groupadd git useradd git -g git 2.创建authorized_keys cd /home/git mkdir .ss ...
- UEditor 在 Layer 模态框中无法使用问题
问题: 解决方法: 在 使用 ueditor 的页面顶部加入js代码: window.UEDITOR_HOME_URL = "__STATIC__/path/to/ueditor/&quo ...
- p2.BTC-数据结构
hash pointers:哈希指针,除了保存值的地址,还要存这整个区块的内容的hash值.这样就既能访问到值,还能确定访问的值有没有被篡改. 一 Blockchain Block chain is ...
- git 分支查看与切换
git 分支查看与切换 # 1.查看所有分支 > git branch -a # 2.查看当前使用分支(结果列表中前面标*号的表示当前使用分支) > git branch # 3.切换分支 ...
- CentOS7安装Redis单实例
由于环境差异,安装过程可能遇到各种各样的问题,不要慌,根据错误提示解决即可. 1.下载redis下载地址在:redis.io比如把Redis安装到/usr/local/soft/ cd /usr/lo ...
- destoon二次开发-用户名、邮箱、手机账号中间字符串以*隐藏 扩展
因为dt里面有用户名.邮箱.手机账号等,所以想办法进行隐藏保护用户隐私,所以个人就试着写了这个代码. 在api/extend.func.php文件下增加以下代码: //用户名.邮箱.手机账号中间字符串 ...
- 【Python学习】Python3 基础语法
==================================================================================================== ...
- Spring源码窥探之:Condition
采用注解的方式来注入bean 1. 编写config类 /** * @author 70KG * @Title: ConditionConfig * @Description: * @date 201 ...
- dp--01背包,完全背包,多重背包
背包问题 以下代码 n是物品个数,m是背包容积 物品价值和重量int v[maxn],w[maxn]; 01背包 模板 for(int i = 0; i < n; i++) { for(int ...
- BlockingCollection<T> 类实现 列队操作
官方文档 为实现 IProducerConsumerCollection<T> 的线程安全集合提供阻塞和限制功能. 通过 BlockingCollection<T> 实现列队调 ...