Coder Social home page Coder Social logo

Comments (3)

chhaude avatar chhaude commented on August 29, 2024

The behavior now is better. However, one issue remains in when trying to connect to an unreachable host:
The event OnError cannot be connected to before the connection is being established.

Detailed description:
When the constructor WebChannelTcpSocketTransport is called, the connection is established even before any event handlers can be connected to.

public WebChannelTcpSocketTransport(string host, int port, Action<WebChannelTcpSocketTransport> connectedCallback) {
            sock = new TcpClient();
            sock.BeginConnect(host, port, new AsyncCallback(ClientConnected), connectedCallback);
        }

Consequently, the OnError handler is for sure not set, so in any case only the message "An error occured while attempting to connect!" will appear, and OnError(this, args); will never be called.

void ClientConnected(IAsyncResult ar)
        {
            var callback = (Action<WebChannelTcpSocketTransport>) ar.AsyncState;
            try {
                sock.EndConnect(ar);
            } catch (Exception e) {
                Console.Error.WriteLine("An error occured while attempting to connect!");
                if (OnError != null) {
                    var args = new UnhandledExceptionEventArgs(e, false);
                    OnError(this, args);
                }
                return;
            }
.
.
.

I suggest to change the architecture a little, so that the constructor doesn't immediately establish the connection, but rather returns the object. Then event handlers can be set, and afterwards the connection can be established by a publish function connect() or similar.

from webchannel.net.

chhaude avatar chhaude commented on August 29, 2024

I found another problem: When calling the Dispose()-function and data is received at that time, the exception handlers don't catch all exceptions:

Unbehandelte Ausnahme: System.ObjectDisposedException: Auf das verworfene Objekt kann nicht zugegriffen werden.
Objektname: "System.Net.Sockets.Socket".
   bei System.Net.Sockets.Socket.Poll(Int32 microSeconds, SelectMode mode)
   bei QWebChannel.WebChannelTcpSocketTransport.IsSocketConnected(Socket s)
   bei QWebChannel.WebChannelTcpSocketTransport.DataAvailable(IAsyncResult ar)
   bei System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Net.ContextAwareResult.Complete(IntPtr userToken)
   bei System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   bei System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   bei System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

The call to IsSocketConnected fails, and this is a function that is not within a try-block.
The same happens for the Disconnect()-function.

I believe we need to fix those problems before we can really release the library for general use.

from webchannel.net.

msarehn avatar msarehn commented on August 29, 2024

These should be fixed now with the latest two commits.

from webchannel.net.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.