Exemple #1
0
 public ObexServer(IInputStream inputStream, IOutputStream outputStream, ObexServiceUuid serviceUuid)
 {
     _reader      = new DataReader(inputStream);
     _writer      = new DataWriter(outputStream);
     _serviceUuid = serviceUuid;
     _cts         = new CancellationTokenSource();
 }
Exemple #2
0
 public ObexConnectPacket(bool disconnect, ObexServiceUuid targetService) : base(disconnect ? Opcode.Disconnect : Opcode.Connect)
 {
     if (disconnect)
     {
         Opcode = Opcode.Disconnect;
     }
     else
     {
         Opcode = Opcode.Connect;
     }
     Headers[HeaderId.Target] = new BytesHeader(HeaderId.Target, targetService.Value);
 }
Exemple #3
0
        /// <summary>
        /// Send OBEX Connect packet to the server.
        /// </summary>
        /// <param name="targetUuid">A 16-length byte array indicates the UUID of the target service.</param>
        /// <exception cref="InvalidOperationException">The Connect method can call only once and it is already called before.</exception>
        /// <exception cref="ObexRequestException">The request failed due to an underlying issue such as connection issue, or the server reply with a invalid response</exception>
        public async Task Connect(ObexServiceUuid targetService)
        {
            if (Conntected)
            {
                throw new InvalidOperationException("ObexClient is already connected to a ObexServer");
            }

            ObexConnectPacket packet = new ObexConnectPacket(targetService);
            var buf = packet.ToBuffer();

            Console.WriteLine("Sending OBEX Connection request to server:");
            Console.WriteLine(BitConverter.ToString(buf.ToArray()));
            Console.WriteLine("Opcode: " + packet.Opcode);

            _writer.WriteBuffer(buf);
            await _writer.StoreAsync();

            Console.WriteLine("Waiting reply packet...");
            ObexPacket response = await ObexPacket.ReadFromStream(_reader, packet);

            var bytes = response.ToBuffer().ToArray();

            Console.WriteLine("Reply packet:");
            Console.WriteLine(BitConverter.ToString(bytes));
            Console.WriteLine($"ResponseCode: {response.Opcode}");
            response.PrintHeaders();

            if (response.Opcode != Opcode.Success && response.Opcode != Opcode.SuccessAlt)
            {
                throw new ObexRequestException($"Unable to connect to the target OBEX service.", response.Opcode);
            }

            if (response.Headers.ContainsKey(HeaderId.ConnectionId))
            {
                _connectionIdHeader = (Int32ValueHeader)response.Headers[HeaderId.ConnectionId];
            }
            Conntected = true;
        }
Exemple #4
0
 public ObexConnectPacket(ObexServiceUuid targetService) : this(false, targetService)
 {
 }