1.10. Tracking Partners With Cookies

Sometimes a server needs some session management to keep track of the clients involved. One solution would be, to add an extra parameter representing some unique identifier to each method invocation and return value. But this means additional work for each possible method call.

A more convenient solution when using HTTP as transportation media is to apply cookie management. In this case the server checks the incoming HTTP header for a special line with session information. This is called a cookie. If the information is missing, the server adds one to the response. The client is then expected to store the cookie and add it to further requests if appropriate.

1.10.1. Cookies in Server Mode

To use cookies on the server side the following steps are needed:


  TcpIpConnection conn (true, host, port);
  HttpProtocol prot(&conn);

  prot.setAcceptCookies(true);  1

  if (prot.hasCookie()) 2
    prot.getCookie();

  prot.setServerCookie("cookie-test=123"); 3

1

Enable cookie managent. Otherwise cookies are completely ignored.

2

Check for incoming cookie information and use it.

3

Add a cookie to further responses over this protocol object.