Exemplo n.º 1
0
        private void _adapter_ErrorOccured(object sender, SocketHelper.Events.ErrorEventArgs args)
        {
            string errMsg = "";

            if (_linker != null)
            {
                errMsg = "URL:" + _linker.StreamUri + ";";
            }
            errMsg += args.ErrorMessage;
            Logger.Default.Error(errMsg);
            _adapter.Close();
        }
Exemplo n.º 2
0
        private void Adapter_ErrorOccured(object sender, SocketHelper.Events.ErrorEventArgs args)
        {
            SocketAdapter adapter = sender as SocketAdapter;

            Console.WriteLine("Adapter ErrorOccured:" + args.ErrorMessage + "__" + adapter.RemoteEndPoint);
            adapter.Close();
        }
Exemplo n.º 3
0
        private void onErrorOccured(object sender, SocketHelper.Events.ErrorEventArgs args)
        {
            SocketAdapter adapter = sender as SocketAdapter;

            Logger.Default.Debug("Adapter ErrorOccured:" + args.ErrorMessage + "__" + adapter.RemoteEndPoint);
            adapter.Close();
        }
        private void onErrorOccured(object sender, SocketHelper.Events.ErrorEventArgs args)
        {
            SocketAdapter adapter = sender as SocketAdapter;

            Common.Log.Logger.Default.Trace($"Adapter ErrorOccured:{ConnectInfom} {args.ErrorMessage} __{adapter.RemoteEndPoint}");
            adapter.Close();
        }
Exemplo n.º 5
0
        internal ObexListenerContext(SocketAdapter s)
        {
            buffer = new byte[0x2000];

            this.localEndPoint  = s.LocalEndPoint;
            this.remoteEndPoint = s.RemoteEndPoint;

            bool moretoreceive = true;
            bool putCompleted  = false;

            while (moretoreceive)
            {
                //receive the request and store the data for the request object
                int received = 0;

                try {
                    while (received < 3)
                    {
                        int readLen = s.Receive(buffer, received, 3 - received, SocketFlags.None);
                        if (readLen == 0)
                        {
                            moretoreceive = false;
                            if (received == 0)
                            {
                                break; // Waiting for first byte of packet -- OK to close then.
                            }
                            else
                            {
                                throw new EndOfStreamException("Connection lost.");
                            }
                        }
                        received += readLen;
                    }
                    //Debug.WriteLine(s.GetHashCode().ToString("X8") + ": RecvH", "ObexListener");
                } catch (SocketException se) {
                    //Console.Write(se.Message);
                    HandleConnectionError(se);
                }

                if (received == 3)
                {
                    ObexMethod method = (ObexMethod)buffer[0];
                    //get length (excluding the 3 byte header)
                    short len = (short)(IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 1)) - 3);
                    if (len > 0)
                    {
                        int iPos = 0;

                        while (iPos < len)
                        {
                            int wanted = len - iPos;
                            Debug.Assert(wanted > 0, "NOT wanted > 0, is: " + wanted);
                            int receivedBytes = s.Receive(this.buffer, iPos + 3, wanted, SocketFlags.None);
                            if (receivedBytes == 0)
                            {
                                moretoreceive = false;
                                throw new EndOfStreamException("Connection lost.");
                            }
                            iPos += receivedBytes;
                        }
                    }

                    byte[] responsePacket; // Don't init, then the compiler will check that it's set below.

                    //Debug.WriteLine(s.GetHashCode().ToString("X8") + ": Method: " + method, "ObexListener");
                    responsePacket = HandleAndMakeResponse(ref moretoreceive, ref putCompleted, method);

                    try {
                        System.Diagnostics.Debug.Assert(responsePacket != null, "Must always respond to the peer.");
                        if (responsePacket != null)
                        {
                            s.Send(responsePacket);
                        }
                    } catch (Exception se) {
                        //Console.WriteLine(se.Message);
                        HandleConnectionError(se);
                    }
                }
                else
                {
                    moretoreceive = false;
                }
            }//while

            Debug.WriteLine(s.GetHashCode().ToString("X8") + ": Completed", "ObexListener");
            s.Close();
            s = null;

            if (!putCompleted)
            {
                // Should not return the request.
                throw new ProtocolViolationException("No PutFinal received.");
            }
            request = new ObexListenerRequest(bodyStream.ToArray(), headers, localEndPoint, remoteEndPoint);
        }
Exemplo n.º 6
0
 private void _adapter_ErrorOccured(object sender, SocketHelper.Events.ErrorEventArgs args)
 {
     _adapter.Close();
 }