Server Operations

To act as a server you must first tell the transport to receive incoming connections via the function OBEX_ServerRegister. When an incoming connection is coming you'll get an OBEX_EV_ACCEPTHINT event. If you ignore this event no more incoming connections will be accepted, but if you call OBEX_Accept you'll get back a new OBEX handle and the old handle will still be listening to connections.

When an incoming request comes you'll first get an OBEX_EV_REQHINT event. The supplied OBEX Object is allocated by the library so you do not need to create it yourself.

The OBEX_EV_REQHINT event comes before the parser start receiving the request, so you can cancel requests that your application does not support early.

Set the response to the request using OBEX_ObjectSetRsp

You can tell the parser to deliver the body-header as a stream when this event comes using OBEX_ObjectReadStream

When the request is received you'll get an OBEX_EV_REQ event. Get the headers from the object by calling OBEX_GetNextHeader. You can now change the response if you decide to reject the request. Add any headers you want in the response here too.

When your response is successfully sent you'll get an OBEX_EV_REQDONE event.

After you have received and answered an OBEX Disconnect request you shall call OBEX_TransportDisconnect

Example 2. Event callback of a typical server

  switch (event)	{
  case OBEX_EV_REQ:
      /* An incoming request */
      switch(obex_cmd) {
      case OBEX_CMD_CONNECT:
      case OBEX_CMD_DISCONNECT:
      /* Dont need to do anything here.
         Response is already set to
         success by OBEX_EV_REQHINT event */
          break;
      case OBEX_CMD_PUT:
          deliver_put_to_app(object);
          break;
      }			
      break;

  case OBEX_EV_REQHINT:

      /* A new request is coming in */
      switch(obex_cmd) {
      /* Accept xome commands! */
      case OBEX_CMD_PUT:
      case OBEX_CMD_CONNECT:
      case OBEX_CMD_DISCONNECT:
          OBEX_ObjectSetRsp(object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
          break;
		
      default:
          /* Reject any other commands */			
          OBEX_ObjectSetRsp(object, OBEX_RSP_NOT_IMPLEMENTED,
          			OBEX_RSP_NOT_IMPLEMENTED);
              break;
		
      }
      break;

  case OBEX_EV_REQDONE:
      if(obex_cmd == OBEX_CMD_DISCONNECT) {
          /* Disconnect transport here */
      }
      break;

  case OBEX_EV_LINKERR:
      /* Not good */
      break;

  default:
      break;
  }