相关疑难解决方法(0)

由于线程退出或应用程序请求,I/O操作已中止

我的应用程序作为银行服务器的客户端应用程序.应用程序正在发送请求并从银行获得响应.这个应用程序通常工作正常,但有时

由于线程退出或应用程序请求,I/O操作已中止

错误代码为995即将发生.

public void OnDataReceived(IAsyncResult asyn)
{
    BLCommonFunctions.WriteLogger(0, "In :- OnDataReceived", 
                                        ref swReceivedLogWriter, strLogPath, 0);
    try
    {
        SocketPacket theSockId = (SocketPacket)asyn.AsyncState;

        int iRx = theSockId.thisSocket.EndReceive(asyn); //Here error is coming
        string strHEX = BLCommonFunctions.ByteArrToHex(theSockId.dataBuffer);                    

    }
}
Run Code Online (Sandbox Code Playgroud)

在相同的错误开始出现后,所有事务开始出现此错误,请帮助我解决此问题.如果可能,那么使用一些示例代码

此致,Ashish Khandelwal

c# sockets exception

14
推荐指数
3
解决办法
7万
查看次数

.net WebSocket:CloseOutputAsync vs CloseAsync

我们有一个有效的ASP.NET Web API REST服务,它使用HttpContext.AcceptWebSocketResponse(..)在我们的控制器方法之一上使用WebSockets.

套接字处理程序代码看起来像这样......

public async Task SocketHandler(AspNetWebSocketContext context)
{
    _webSocket = context.WebSocket;
    ...
    while(!cts.IsCancellationRequested)
    {
        WebSocketReceiveResult result = _webSocket.ReceiveAsync(inputSegment, cts.Token).Result;
        WebSocketState currentSocketState = _webSocket.State;

        if (result.MessageType == WebSocketMessageType.Close ||
            currentSocketState == WebSocketState.CloseReceived)
        {
            // Should I use .CloseAysnc() or .CloseOutputAsync()?
            _webSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "client requested", cts.Token).Wait();
        }

        if (currentSocketState == WebSocketState.Open)
        {
        ...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

.CloseAsync()和CloseOutputAysnc()之间有什么区别?我试过两个,他们似乎都很好,但必须有一些区别.它们在MSDN上都有非常相似的描述......

System.Net.WebSockets.CloseAsync - 使用WebSocket协议规范第7节中定义的关闭握手将WebSocket连接关闭为异步操作.

System.Net.WebSockets.CloseOutputAsync - 启动或完成WebSocket协议规范第7节中定义的关闭握手.

.net c# websocket asp.net-web-api

8
推荐指数
1
解决办法
4085
查看次数

标签 统计

c# ×2

.net ×1

asp.net-web-api ×1

exception ×1

sockets ×1

websocket ×1