zyanfx / Zyan

:gem: Zyan Communication Framework
http://zyan.com.de
MIT License
88 stars 38 forks source link

Error receiving message; Zyan.Communication.Protocols.Tcp.DuplexChannel.MessageException: Connection closed. ---> System.Net.Sockets.SocketException #51

Closed BLIZZARD123 closed 5 years ago

BLIZZARD123 commented 5 years ago

Dear all,

I'm trying to implement the Zyan TCP duplex scenario with one server (as a windows service) and two clients. Currently I'm using Zyan 2.11 and SafeDeserializationHelpers v0.5

Ok let me explain which issue i face. I created the server as a windows service with the following code: ` private ZyanComponentHost server;

    public MT5TerminalServer()
    {
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {
        TcpDuplexServerProtocolSetup protocol = new TcpDuplexServerProtocolSetup(Constants.ZYAN_PORT, null, true);
        server = new ZyanComponentHost(Constants.ZYAN_CHANNEL, protocol);
        server.RegisterComponent<ISharedObject, SharedObject>(ActivationType.Singleton);
        //server.EnableDiscovery();
    }

`

Constants:

` public const int ZYAN_PORT = 8081;

    public const string ZYAN_SERVER = "localhost";

    public const string ZYAN_CHANNEL = "MT5Terminal";

public static string GetServerAddress() { return string.Format("tcpex://{0}:{1}/{2}", Constants.ZYAN_SERVER, Constants.ZYAN_PORT, Constants.ZYAN_CHANNEL); }`

My SharedObject looks like `public interface ISharedObject {

region Properties

    SymbolInfo SymbolInfo { get; set; }
    OrderQueue OrderQueue { get; set; }
    AccountInfo AccountInfo { get; set; }
    Chart Chart { get; set; }
    TerminalEvent TerminalEvent { get; set; }
    Preferences Preferences { get; set; }
    Fibo Fibo { get; set; }
    #endregion

    #region Events
    event Action<SymbolInfo> SymbolChanged;
    event Action<SymbolInfo> NewSymbolSelected;
    event Action<Chart, Chart> NewChartOpened;
    event Action<Chart> ChartClosed;
    #endregion
}`

My clients are connecting with `ZyanConnection connection = null; TcpDuplexClientProtocolSetup protocol = new TcpDuplexClientProtocolSetup(true);

            try
            {
                connection = new ZyanConnection(Functions.GetServerAddress(), protocol);

                ISharedObject proxy = connection.CreateProxy<ISharedObject>();
                proxy.SymbolInfo = new SymbolInfo(symbolInfo);
                proxy.AccountInfo = new AccountInfo(accountInfo);
                proxy.Chart = new Chart(chart);

                return_code = (int)ENUM_LIBRARY_RCODE.RCODE_OK;
            }
            catch (Exception e)
            {
                Logger.AppendMessageToEventLog(ENUM_LOGGER.LOGGER_TERMINAL, e);

                return_code = (int)ENUM_LIBRARY_RCODE.RCODE_FAILED;
            }`

But at line proxy.SymbolInfo = new SymbolInfo(symbolInfo);

i get the following error message `mscorlib; Error receiving message; Zyan.Communication.Protocols.Tcp.DuplexChannel.MessageException: Connection closed. ---> System.Net.Sockets.SocketException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen --- Ende der internen Ausnahmestapelüberwachung --- bei Zyan.Communication.Protocols.Tcp.DuplexChannel.Message.EndReceive(Connection& connection, IAsyncResult ar) in D:\Externals\Zyan\source\Zyan.Communication\Protocols\Tcp\DuplexChannel\Message.cs:Zeile 176.; Server stack trace: bei Zyan.Communication.Protocols.Tcp.DuplexChannel.Message.EndReceive(Connection& connection, IAsyncResult ar) in D:\Externals\Zyan\source\Zyan.Communication\Protocols\Tcp\DuplexChannel\Message.cs:Zeile 222. bei Zyan.Communication.Protocols.Tcp.DuplexChannel.Manager.ReceiveMessage(IAsyncResult ar) in D:\Externals\Zyan\source\Zyan.Communication\Protocols\Tcp\DuplexChannel\Manager.cs:Zeile 310. bei Zyan.Communication.Protocols.Tcp.DuplexChannel.Manager.EndReadMessage(Connection& connection, IAsyncResult ar) in D:\Externals\Zyan\source\Zyan.Communication\Protocols\Tcp\DuplexChannel\Manager.cs:Zeile 415. bei Zyan.Communication.Protocols.Tcp.DuplexChannel.ClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream) in D:\Externals\Zyan\source\Zyan.Communication\Protocols\Tcp\DuplexChannel\ClientTransportSink.cs:Zeile 98. bei Zyan.Communication.ChannelSinks.Encryption.CryptoClientChannelSink.ProcessEncryptedMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream) in D:\Externals\Zyan\source\Zyan.Communication\ChannelSinks\Encryption\CryptoClientChannelSink.cs:Zeile 225. bei Zyan.Communication.ChannelSinks.Encryption.CryptoClientChannelSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream) in D:\Externals\Zyan\source\Zyan.Communication\ChannelSinks\Encryption\CryptoClientChannelSink.cs:Zeile 258. bei Zyan.Communication.ChannelSinks.Compression.CompressionClientChannelSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream) in D:\Externals\Zyan\source\Zyan.Communication\ChannelSinks\Compression\CompressionClientChannelSink.cs:Zeile 175. bei Zyan.SafeDeserializationHelpers.Channels.SafeBinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) bei Zyan.Communication.IZyanDispatcher.Invoke(Guid trackingID, String interfaceName, List`1 delegateCorrelationSet, String methodName, Type[] genericArguments, Type[] paramTypes, Object[] args) bei Zyan.Communication.ZyanProxy.InvokeRemoteMethod(IMethodCallMessage methodCallMessage) in D:\Externals\Zyan\source\Zyan.Communication\ZyanProxy.cs:Zeile 560.

Exception rethrown at [1]: bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) bei MT5Library.TerminalCommunication.ISharedObject.set_SymbolInfo(SymbolInfo value) bei MT5Library.MT5Library.SendData(MT5SymbolInfo& symbolInfo, MT5AccountInfo& accountInfo, MT5Chart& chart) in D:\Dropbox\Documents\Visual Studio 2017\source\repos\MT5_V2P0\MT5Library\MT5Library.cs:Zeile 36.; Zyan.Communication.Protocols.Tcp.DuplexChannel.MessageException: Error receiving message ---> Zyan.Communication.Protocols.Tcp.DuplexChannel.MessageException: Connection closed. ---> System.Net.Sockets.SocketException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen --- Ende der internen Ausnahmestapelüberwachung --- bei Zyan.Communication.Protocols.Tcp.DuplexChannel.Message.EndReceive(Connection& connection, IAsyncResult ar) in D:\Externals\Zyan\source\Zyan.Communication\Protocols\Tcp\DuplexChannel\Message.cs:Zeile 176. --- Ende der internen Ausnahmestapelüberwachung ---

Server stack trace: bei Zyan.Communication.Protocols.Tcp.DuplexChannel.Message.EndReceive(Connection& connection, IAsyncResult ar) in D:\Externals\Zyan\source\Zyan.Communication\Protocols\Tcp\DuplexChannel\Message.cs:Zeile 222. bei Zyan.Communication.Protocols.Tcp.DuplexChannel.Manager.ReceiveMessage(IAsyncResult ar) in D:\Externals\Zyan\source\Zyan.Communication\Protocols\Tcp\DuplexChannel\Manager.cs:Zeile 310. bei Zyan.Communication.Protocols.Tcp.DuplexChannel.Manager.EndReadMessage(Connection& connection, IAsyncResult ar) in D:\Externals\Zyan\source\Zyan.Communication\Protocols\Tcp\DuplexChannel\Manager.cs:Zeile 415. bei Zyan.Communication.Protocols.Tcp.DuplexChannel.ClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream) in D:\Externals\Zyan\source\Zyan.Communication\Protocols\Tcp\DuplexChannel\ClientTransportSink.cs:Zeile 98. bei Zyan.Communication.ChannelSinks.Encryption.CryptoClientChannelSink.ProcessEncryptedMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream) in D:\Externals\Zyan\source\Zyan.Communication\ChannelSinks\Encryption\CryptoClientChannelSink.cs:Zeile 225. bei Zyan.Communication.ChannelSinks.Encryption.CryptoClientChannelSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream) in D:\Externals\Zyan\source\Zyan.Communication\ChannelSinks\Encryption\CryptoClientChannelSink.cs:Zeile 258. bei Zyan.Communication.ChannelSinks.Compression.CompressionClientChannelSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream) in D:\Externals\Zyan\source\Zyan.Communication\ChannelSinks\Compression\CompressionClientChannelSink.cs:Zeile 175. bei Zyan.SafeDeserializationHelpers.Channels.SafeBinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) bei Zyan.Communication.IZyanDispatcher.Invoke(Guid trackingID, String interfaceName, List`1 delegateCorrelationSet, String methodName, Type[] genericArguments, Type[] paramTypes, Object[] args) bei Zyan.Communication.ZyanProxy.InvokeRemoteMethod(IMethodCallMessage methodCallMessage) in D:\Externals\Zyan\source\Zyan.Communication\ZyanProxy.cs:Zeile 560.

Exception rethrown at [1]: bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) bei MT5Library.TerminalCommunication.ISharedObject.set_SymbolInfo(SymbolInfo value) bei MT5Library.MT5Library.SendData(MT5SymbolInfo& symbolInfo, MT5AccountInfo& accountInfo, MT5Chart& chart) in D:\Dropbox\Documents\Visual Studio 2017\source\repos\MT5_V2P0\MT5Library\MT5Library.cs:Zeile 36.`

I really dont know why. I've also deactivated the firewall to check if there is anything blocked, but without success. May you can give me some hints? Thank you!

BR

BLIZZARD123 commented 5 years ago

Ok i finally found the issue by myself, there was a wrong defined setter / getter in SymbolInfo which caused the issue.