Server implementation process based on bluez and obex in Linux

Source: Internet
Author: User

In Linux, the server implementation process based on bluez and obex is as follows:

A server must provide the obex object PUSH Service channel to the other party. Therefore, before opening the server, make sure that the service has been registered to the SDP server. in Linux, the command for registering the service with sdptool is: sdptool add opush;

1. obex_init () is used to initialize an obex instance handle;
Arg1: obex_trans_bluetooth is used to declare that the transmission protocol is Bluetooth;

Arg2: callback function;
Arg3: Flag = obex_fl_keepserver. After receiving the request, the server can continue to receive requests from other clients;

2. obex_setuserdata () sets the user's own variables. The use of this function depends entirely on the user's own;

3. btobex_serverregister (); a Bluetooth-specific server function used to listen to requests sent by the client;
This function creates
Socket (call socket (af_bluetooth, sock_stream,
Btproto_rfcomm), bind the socket to the local Bluetooth address, convert the socket to listen for sockt, then the socket can listen on the port
Connection requests from clients;

4. The obex_handleinput () function is used to read and process received data. If no data arrives, the function will be blocked;
This function calls the selet () function internally and registers the handle client sockt and server sockt to the system to let the system listen to the events on the socket. If data arrives on the server socket, call the accept () function to create a new sockt for the client,
If the flag of obex_init () is not set to obex_fl_keepserver, the socket on the server is disabled to prohibit connection requests from other clients;
(??? :
Accept () creates a new socket for the client and returns its descriptor. Is the port of the newly created socket reallocated? Is it the channel of the original server, such
If it is re-allocated, the service is registered only on the channel of the server. If it is not re-allocated, it means that multiple clients use the same channel) O ...)

5. Callback: obex_ev_accepthint;

6. obex_serveraccept () This function returns the socket of the above client;
The function re-creates an obex instance handle and copies the handle parameter of the above server to the handle. After obtaining the FD (accept is the socket created by the client) of the server handle, clears the FD of the server;
This function also sets the callback function and userdata for the newly created obex instance handle;
So far, an obex instance handle that is completely independent from the server has been created for the client, and operations on the server are identified by the handle, the socket of the server continues to listen for connection requests from other clients;

 

9. Callback: obex_ev_reqdone: obex_assist_connect;

10. Callback: obex_ev_reqhint a request is coming soon;
Call obex_objectsetrsp (object, obex_rsp_continue, obex_rsp_success) to set the response operation code.

11. Callback: obex_ev_reqcheck: The first received request packet has been parsed;
12. Callback: obex_ev_progress (if n events are received, the client is transmitting the file content );
13. Callback: obex_ev_req: obex_pai_put;
Obex_objectsetrsp (object, obex_rsp_continue, obex_rsp_success) sets the response operation code;
At this point, the client file transmission is complete and must be processed:
Obex_objectgetnextheader () obtains the Object Name and content respectively;

14. Callback: obex_ev_reqdone: obex_pai_put;

15. Callback: obex_ev_reqhint a request is coming soon
16. Callback: obex_ev_req: obex_assist_disconnect
Obex_objectsetrsp (object, obex_rsp_success, obex_rsp_success) sets the response operation code;

17. Callback: obex_ev_reqdone: obex_assist_disconnect;
Obex_transportdisconnect (handle) is disconnected;
Note: This function only closes the socket and does not release the resources occupied by handle. Therefore, you need to release the resources occupied by handle during application;

18. obex_cleanup (): Turn off obex handle and release the resources occupied by this handle.
(This function also closes the client and server socket );

At this point, the server has completed an example of receiving the client.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.