longshine / mina.net Goto Github PK
View Code? Open in Web Editor NEW.NET implementation of Apache MINA
License: Apache License 2.0
.NET implementation of Apache MINA
License: Apache License 2.0
Seems to be a mis-implementation of ISocketConnector
.
If a connection is closed by the remote peer, a session may be stopped without being removed and notifying SessionClosed
event, in which case the application will never know that this session has been terminated.
This is caused by incorrectly handling Socket Errors in SocketAsyncEventArgs.Completed
callbacks, where SocketError.OperationAborted
& SocketError.Interrupted
are falsely ignored.
Commit d97272f fixes this issue.
No backward compatibility problems are expected.
If you cannot upgrade to latest code, you can apply below workarounds:
If messages are written to a session whose underlying socket is actually disconnected, you can expect a WriteToClosedSessionException
in the ExceptionCaught
event.
我发现有个 Broadcast方法,
IoConnector connector = new AsyncDatagramConnector();
IoBuffer buffer = IoBuffer.Allocate(64);
buffer.Put(data);
buffer.Flip();
connector.Broadcast(buffer);
马上有个异常报错了,Exception:以一种访问权限不允许的方式做了一个访问套接字的尝试。
增加 Socket.EnableBroadcast = true; 就没有异常了
但是我自己写的socket广播,也没有去设置EnableBroadcast ,也没报错。
初略一看,还没发现具体原因是什么。。。。
init
_connector = new AsyncSocketConnector();
_connector.FilterChain.AddLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Encoding.UTF8)));
_connector.FilterChain.AddLast("logger", new Log4UnityFilter());
_connector.FilterChain.AddLast("json", new JsonFilter());
_connector.FilterChain.AddLast("error", new ErrorMessageFilter());
_connector.FilterChain.AddLast("identity", new IdentityFilter(deviceType));
_connector.Handler = new SyncSendReceiveHandler();
Filter
public class ErrorMessageFilter : IoFilterAdapter
{
public override void MessageReceived(INextFilter nextFilter, IoSession session, object message)
{
ResponseMessage response = message as ResponseMessage;
if (response == null)
nextFilter.ExceptionCaught(session, new Exception("Wrong Used"));
if(response.Error != null)
{
Exception cause = new Exception("[code]:" + response.Error.Code + " [message]:" + response.Error.Message);
throw cause; // HERE
nextFilter.ExceptionCaught(session, cause);
}
nextFilter.MessageReceived(session, message);
}
}
并没有执行Handler
当throw Exception时,进入到DefaultIoFilterChain中的
private void CallNext(IEntry<IoFilter, INextFilter> entry, Action<IoFilter, INextFilter> act, Action<Exception> error = null)
{
try
{
IoFilter filter = entry.Filter;
INextFilter nextFilter = entry.NextFilter;
act(filter, nextFilter);
}
catch (Exception ex)
{
if (error == null)
this.FireExceptionCaught(ex);
else
error(ex);
}
}
进入FireExceptionCaught(ex),但是之后过后,并没有进入Handler
In some cases, sessions of unexpectedly lost connections are not correctly removed. This will lead to a high memory consumption and cause the servcie to be unavailable to new connections.
Commit 37073ce and 587ab95 fixed this issue.
If you cannot upgrade to latest code, you can apply below workarounds:
ExceptionCaught
eventMake sure to close the related session by calling Session.Close()
if you get a SocketException
.
No backward compatibility problems are expected.
现象:客户端成功连接服务端建立了Session,利用此session客户端发起的请求能收到服务端的应答;但后续服务端利用此session发起请求到客户端,会导致session关闭。
问题:请教mina.net是否支持双向通信?支持的话,怎么利用已建立的session,由服务端主动向客户端发起请求。
hi
2 days ago you update core with new futures.(Updated the writeRequests future when the session is destroyed)
please update nuget package.
thanks
程序正在接收大量数据时,如果突然断开网络,AsyncSocketSession.NET20.cs中BeginSend中的Socket.BeginSend(array.Array, array.Offset, array.Count, SocketFlags.None, SendCallback, new SendingContext(Socket, buf)); 方法会抛出SocketException异常,导致程序崩溃
服务端使用AsyncSocketAcceptor监听端口时,在IMessageDecoder.Decode方法中出现
"Mina.Core.Buffer.BufferUnderflowException: 引发类型为“Mina.Core.Buffer.BufferUnderflowException”的异常。 在 Mina.Core.Buffer.Buffer.NextGetIndex(Int32 nb) 在 Mina.Core.Buffer.AbstractIoBuffer.GetInt32() 。"的错误,该错误发生时有用catch{}try{}捕捉处理该异常。但是新的客户端请求连接的时候服务端无法监听到,客户端返回"System.Net.SocketException(0x80004005):由于目标计算机积极拒绝,无法连接。"的错误。
观察服务端端口状态为Listening,重启服务端后客户端即可正常连接服务端。
请问该如何解决这个问题?谢谢!
In SocketSession.BeginSend()
, if a non-IoBuffer
or non-IFileRegion
message is detected, an InvalidOperationException
will be thrown into the EndSend()
method, in which the BeginSend()
will be fired again, while keeping the same faulty message as current request. This would lead to an infinite loop.
End sending and discard the current writing request if the message cannot be sent.
Commit 9616e9b fixed this issue.
No backward compatibility problems are expected.
程序在不稳定的网络环境下长时间运行时,偶遇如下异常:
System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled未处理的异常同步模块.vshost.exeSystem.Net.Sockets.SocketException, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089系统检测到在一个调用中尝试使用指针参数时的无效指针地址。 在 System.Net.Sockets.Socket.get_RemoteEndPoint()
在 Mina.Transport.Socket.AsyncSocketSession..ctor(IoService service, IoProcessor1 processor, Socket socket, Boolean reuseBuffer) 位置 D:\coding\vs2015\Mina.NET\Mina.NET\Transport\Socket\AsyncSocketSession.NET20.cs:行号 21 在 Mina.Transport.Socket.AsyncSocketConnector.ConnectCallback(IAsyncResult ar) 位置 D:\coding\vs2015\Mina.NET\Mina.NET\Transport\Socket\AsyncSocketConnector.NET20.cs:行号 52 在 System.Net.LazyAsyncResult.Complete(IntPtr userToken) 在 System.Net.ContextAwareResult.CompleteCallback(Object state) 在 System.Threading.ExecutionContext.runTryCode(Object userData) 在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Net.ContextAwareResult.Complete(IntPtr userToken) 在 System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) 在 System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)</StackTrace><ExceptionString>System.Net.Sockets.SocketException: 系统检测到在一个调用中尝试使用指针参数时的无效指针地址。 在 System.Net.Sockets.Socket.get_RemoteEndPoint() 在 Mina.Transport.Socket.AsyncSocketSession..ctor(IoService service, IoProcessor
1 processor, Socket socket, Boolean reuseBuffer) 位置 D:\coding\vs2015\Mina.NET\Mina.NET\Transport\Socket\AsyncSocketSession.NET20.cs:行号 21
在 Mina.Transport.Socket.AsyncSocketConnector.ConnectCallback(IAsyncResult ar) 位置 D:\coding\vs2015\Mina.NET\Mina.NET\Transport\Socket\AsyncSocketConnector.NET20.cs:行号 52
在 System.Net.LazyAsyncResult.Complete(IntPtr userToken)
在 System.Net.ContextAwareResult.CompleteCallback(Object state)
在 System.Threading.ExecutionContext.runTryCode(Object userData)
在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Net.ContextAwareResult.Complete(IntPtr userToken)
在 System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
在 System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)271E
Do you plan to implement the existing Apache CompresionFilter?
I tried to do, but buffers confuse me
The enum type IoEventType
is not defined with bit-masked flags, causing all modules that rely on it fail to work properly, including ExecutorFilter
with specific event types, WriteRequestFilter
, ProfilerTimerFilter
, CommonEventFilter
, and the Loopback
transport.
Commit b02d967 fixed this issue.
No backward compatibility problems are expected.
Seems to be a mis-implementation of ISocketConnector
.
The encoder output would be mixed up if multiple ProtocolCodecFilter
s are put into one same filter chain, since they share the same encoder/decoder outputs because of the same attribute keys.
The constructor of AttributeKey
calls GetHashCode()
, which will always returns (17 * 37) since the _name
filed has NOT been set yet.
No backward compatibility problems are expected.
System.TypeLoadException: Method 'Mina.Core.Filterchain.Chain`3.GetEntry' on type 'Mina.Core.Filterchain.DefaultIoFilterChain'
tried to implicitly implement an interface method with weaker type parameter constraints.
I searched the documentation and could not find any notes on the order of write operations.
Is the order of an Asynchronous Write guaranteed? Or would an Await() be needed after each to guarantee order?
The AsyncSocketAcceptor
(for .NET 4.0) listens to the SessionDestroyed
event of a session, and returns its buffers for reading and writing to the buffer pool for reuse when it has been destroyed. This is how the reusable SocketAsyncEventArgs
works, and it works fine, most time.
Normally the SessionDestroyed
event will be fired after the socket closes.
However, since the socket is working asynchronously, the close operation may have not completely been done until some time later. Hence, the buffers returned to the pool may still be in use, making it inconsistent.
If a newly accepted session accquires one of those buffers and tries to begin receiving operation on it, it will throw a InvalidOperationException
saying "A socket operation was already in progress".
Although the receiving operation will be started again even an exception occurs, this may be severe in high-load environment.
No backward compatibility problems are expected.
Uncaught exceptions in BeginSend(IWriteRequest, IoBuffer)
and BeginReceive()
methods in SocketSession
will cause a crush.
Commit 37073ce fixed this issue.
No backward compatibility problems are expected.
Hello i've noticed an issue on my Mina.Net based server, after awhile my server starts receiving data in small chunks instead of the full capacity of the buffer. I've traced the issue down to SocketAsyncEventArgsBuffer, the .Clear() method which is called prior to any receive, has no real effect on Capacity (as it returns _socketAsyncEventArgs.Count) and it may lead to performance degradation.
thanks
geo
Add Multicast support to DatagramAcceptor
and DatagramConnector
.
See http://msdn.microsoft.com/en-us/library/system.net.sockets.multicastoption%28v=vs.110%29.aspx.
No backward compatibility problems are expected.
由于Unity3d默认使用的是.Net 2.0版本,由于Commons.Log官方最低版本升级到.Net 3.5直接导致使用NuGet引入Mina.Net时,自动引入的Commons.Log .Net3.5发生.Net版本错误
Hi.
it is better to update to Mina 2.1.5 and use .net 6 for more performance.
can anybody update it?
First day try Mina.NET , try Udp Client Demo.
But throw exception:
I found 62line in code = "read = socket.EndReceiveFrom(ar, ref remoteEP);"
private void ReceiveCallback(IAsyncResult ar)
{
System.Net.Sockets.Socket socket = (System.Net.Sockets.Socket)ar.AsyncState;
Int32 read = 0;
try
{
EndPoint remoteEP = Socket.RemoteEndPoint;
read = socket.EndReceiveFrom(ar, ref remoteEP);
}
catch (ObjectDisposedException)
{
// do nothing
return;
}
catch (Exception ex)
{
EndReceive(ex);
return;
}
In certain occasion, an uncaught ArgumentOutOfRangeException
may be thrown in method SslHandler.ReadBuffer()
.
This is caused by an invalid count
argument when calling SslStream.Read(byte[] buffer, int offset, int count)
. To avoid overflow, it should be buf.Remaining
, not buf.Capacity
.
Besides, the capacity of buf is incorrectly enlarged.
Related with #15.
Fixes the incorrect count and capacity while reading from a SslStream, and do not write empty buffer into a SslStream.
Commit 5d6fcbd fixed this issue.
No backward compatibility problems are expected.
hi
do you have any example of how to connect client to server using proxy server
thanks
在工作中遇到串口网口通讯统一框架,有没有计划支持.Net core
Instead of begin receiving again, SocketSession.EndReceive(Exception)
faltily calls BeginSend()
. The receiving process will stop, and exceptions might occur if the session has already begun sending.
Fixed in fe857ce.
Most of the time this issue will not cause much trouble, since the method EndReceive(Exception)
is only called in rare cases. If it does, please upgrade to the latest code.
Hi,你好,
我们在使用中发现,如果AsyncDatagramConnector的实例对象调用Connect连接了一个广播地址,之后就无法收取不是从这个地址发出的UDP广播数据。我们尝试了Framework自带的UDPClient,发现不做连接,直接广播,收发一切正常。但是MINA的设计架构似乎一定要先有连接拿到ISession才能做通讯,哪怕是UDP...,因为我们整个系统基于.Net Framework4.0开发,而且必须支持XP,所以我们没法选择DotNetty,貌似Netty是不做连接的。计划用MINA.NET来改写之前的通讯模块,但是现在卡壳这里了,TCP工作的很好,但我们设备检测必须要用UDP,而广播检测消息之后,就无法收到设备的回复了。。。不知能否给些建议来解决这个问题?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.