Comments (6)
这个是.net 内部引发的错误,请问下你是怎样使用beetlex tcp client
from beetlex.
public class TCPCamera
{
private TcpClient client;
private bool TaskIsRunning = true;
static TCPCamera instance;
public Action<string> ReceiveTCP;
public Action<bool> TCPConnectStatus;
public bool IsConnect = false;
public static TCPCamera GetInstance()
{
if (instance == null)
{
instance = new TCPCamera();
}
return instance;
}
public void Connect()
{
Task.Run( () =>
{
RunClient();
});
}
private void RunClient()
{
string ClassName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
string FuncName = System.Reflection.MethodBase.GetCurrentMethod().Name;
string msg = "";
string strmsg1 = $"0 { util.GetNow()} connectCamera ";
App.Log.Info(strmsg1);
string IP = Config.GetInstance().getConfig("CameraIP");
int Port = Convert.ToInt32(Config.GetInstance().getConfig("CameraPort"));
if (client == null)
{
client = SocketFactory.CreateClient<TcpClient>(IP, Port);
client.TimeOut = 300000;
client.Encoding = Encoding.GetEncoding(936);
}
while (TaskIsRunning)
{
try
{
var read = client.Receive();
var str = read.ReadToEnd();
msg = @$"
Class Name [{ClassName}]
Function [{FuncName}]
RecvTime [{util.GetNow()}]
Parameter
Message 接收Vision命令 [{str}]";
App.Log.Info(msg);
ReceiveTCP(str);
TCPConnectStatus(client.IsConnected);
}
catch (Exception e)
{
TCPConnectStatus(false);
msg = @$"
Class Name [{ClassName}]
Function [{FuncName}]
RecvTime [{util.GetNow()}]
Parameter
Message RunClient 视觉网络异常 : {e.Message} HResult: {e.HResult}
";
App.Log.Error(msg);
}
}
}
public void Send(string cmd)
{
try
{
TCPConnectStatus(client.IsConnected);
if (client.IsConnected)
{
client.Stream.ToPipeStream().Write(cmd+"\r\n");
client.Stream.Flush();
string ClassName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
string FuncName = System.Reflection.MethodBase.GetCurrentMethod().Name;
string msg = @$"
Class Name [{ClassName}]
Function [{FuncName}]
RecvTime [{util.GetNow()}]
Parameter
Message 发送命令到视觉 [{cmd}]";
App.Log.Info(msg);
}
else
{
string ClassName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
string FuncName = System.Reflection.MethodBase.GetCurrentMethod().Name;
string msg = @$"
Class Name [{ClassName}]
Function [{FuncName}]
RecvTime [{util.GetNow()}]
Parameter
Message 视觉网络未连接,命令发送失败 [{cmd}]
";
App.Log.Warn(msg);
}
}
catch (Exception ex)
{
string ClassName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
string FuncName = System.Reflection.MethodBase.GetCurrentMethod().Name;
string msg = @$"
Class Name [{ClassName}]
Function [{FuncName}]
RecvTime [{util.GetNow()}]
Parameter
Message 视觉通讯出现异常 [{ex.Message}]";
App.Log.Error(msg);
}
}
public void Dispose()
{
TaskIsRunning = false;
client.DisConnect();
client.Dispose();
client = null;
}
}
from beetlex.
pipestream不是线程安全的,Send方法不能多线程发数据。
看一下具体的socketException errorcode是多什么
from beetlex.
[ 一个封锁操作被对 WSACancelBlockingCall 的调用中断。 HResult: -2147467259]
from beetlex.
看能不能把异常转换成socketexception看对应的errorcode
from beetlex.
找到一个winsock描述,应该是说不要在gui线程中使用对应的同步阻塞
The WSACancelBlockingCall function has been removed in compliance with the Windows Sockets 2 specification, revision 2.2.0.
The function is not exported directly by WS2_32.DLL and Windows Sockets 2 applications should not use this function. Windows Sockets 1.1 applications that call this function are still supported through the WINSOCK.DLL and WSOCK32.DLL.
Blocking hooks are generally used to keep a single-threaded GUI application responsive during calls to blocking functions. Instead of using blocking hooks, an applications should use a separate thread (separate from the main GUI thread) for network activity.
from beetlex.
Related Issues (20)
- 语雀上的收费资料跟微信上的有啥区别嘛 HOT 4
- Need a simple http server code example HOT 2
- BeetleX.Buffers.PipeStream Write 获取buffer偶尔为null HOT 5
- Upgrade to Websocket seems to be broken HOT 1
- AsyncTcpClient 接收不到Disconnected事件 HOT 1
- 能不能保持代码版本同步? HOT 2
- 请问一下呢 HOT 1
- 怎么设置时间呢 HOT 5
- 请问一下,耗时操作 HOT 1
- 内存池用完了,怎么处理? HOT 1
- 服务端发送大文件会丢失4096字节
- server very slow after 5min HOT 1
- TCP merged packets HOT 3
- BeetleX 1.8.0.2 issues about client HOT 1
- 免费版本 (并发响应数: 100) HOT 1
- 将FastHttpAPI的BeetleX的库调整最新的,图片文件等资源会出错 HOT 1
- 升级到net6或者net7 HOT 2
- TCP client certificate can't be added HOT 2
- WriteUTF咨询 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from beetlex.