# Android session timeout

**URL:** https://talk.remobjects.com/t/android-session-timeout/14834
**Category:** Remoting SDK
**Created:** [November 15, 2017, 9:13am UTC](https://talk.remobjects.com/t/android-session-timeout/14834 "2017-11-15T09:13:31Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![dav](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/d/977dab/32.png) [@dav](https://talk.remobjects.com/u/dav)
#### Post date: [November 15, 2017, 9:13am UTC](https://talk.remobjects.com/t/android-session-timeout/14834/1 "2017-11-15T09:13:31Z")

</div>

I am using .NET custom DA server with custom remoting sdk methods in addition into DataService class, remoting sdk methods will use DA login.

On Android native client, an user do a first login and view some datatable from server with DA.  
Session timeout in Server is set to 20 minutes.  
When a timeout occours in android client, i have implemented onLoginNeeded method as documentation for automatically reconnect and it works well.

When timeout occours in client when calling semoting sdk method, onloginneeded is not called.  
There is some way to do the same as DA?

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [November 15, 2017, 10:11am UTC](https://talk.remobjects.com/t/android-session-timeout/14834/2 "2017-11-15T10:11:38Z")

</div>

Could you create a testcase for this issue?

Thanks in advance

---

<div class="post-metadata">

### Author: ![dav](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/d/977dab/32.png) [@dav](https://talk.remobjects.com/u/dav)
#### Post date: [November 15, 2017, 3:28pm UTC](https://talk.remobjects.com/t/android-session-timeout/14834/3 "2017-11-15T15:28:07Z")

</div>

This is client/server NET solution: [WinFormsApplication37\_RemobjectTalkSessionTimeout.zip](https://talk.remobjects.com/uploads/default/original/2X/f/f8c783a421b0e23360dbb0c8cadab458fd34eab9.zip) (4.3 MB)

This is android app: [https://drive.google.com/open?id=1dkm1WyLiSVuH5u-BKb1SL7WPS7eax0TD](https://drive.google.com/open?id=1dkm1WyLiSVuH5u-BKb1SL7WPS7eax0TD)

The server is simple project with added:

- Program.cs  
`server.NetworkServer.SessionManager.Timeout = 1;`
- DataService.cs

> [RemObjects.SDK.Server.ServiceMethod]  
> public DateTime GetUtcNow()  
> {  
> return DateTime.UtcNow;  
> }

Net Client has a working test case to understand what i want to do with android.

Android project is async, so the testcase is reproduced manually.  
On android, when session go in timeout, DataAbstract connection will relogin, but calling remoting sdk method will not reconnect.

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [November 16, 2017, 10:03am UTC](https://talk.remobjects.com/t/android-session-timeout/14834/4 "2017-11-16T10:03:24Z")

</div>

Hello

Thanks for the testcase.

> [@dav](#):
>
> DataAbstract connection will relogin, but calling remoting sdk method will not reconnect.

You did set the ‘relogin needed’ event handler on the data adapter level. When you do call the SDK method you work on the connection channel level and data adapter is not involved. So when the ‘relogin needed’ event is raised there is no handler defined for it.

Adding such handler should rresolve the issue. Sample code:

```
    channelInstance.setChannelCallback(new ClientChannel.IClientChannelCallback() {
        
        @Override
        public boolean clientChannelNeedsLogin(Exception excptn) {
			// TODO Provide here your own login code
            return fDataModule.getDataAdapter().login("123", "123");
        }
        
        // Alternative Login method for connecting to Relativity instance
        /// @Override
        /// public boolean clientChannelNeedsLogin(Exception excptn) {
        /// String RelativityConnectionStringTemplate = "User Id=\"%s\";Password=\"%s\";Domain=\"%s\";Schema=\"%s\"";
        /// String lLoginString = String.format(RelativityConnectionStringTemplate, 
        /// "simple", "simple", "DASamples", "Simple");
        /// return fDataModule.getDataAdapter().login(lLoginString);
        /// }
        
        @Override
        public void requestFailWithException(Exception excptn) {
            // TODO Log exception
        }
    });

```

Regards

---

<div class="post-metadata">

### Author: ![dav](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/d/977dab/32.png) [@dav](https://talk.remobjects.com/u/dav)
#### Post date: [November 16, 2017, 10:53am UTC](https://talk.remobjects.com/t/android-session-timeout/14834/5 "2017-11-16T10:53:33Z")

</div>

I have added this handler, but it give me this exception:

```
 java.net.ProtocolException: cannot write request body after response has been read
                                                                                      at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:267)
                                                                                      at com.remobjects.sdk.HttpClientWorker.Dispatch()
                                                                                      at com.remobjects.sdk.HttpClientAsyncWorker.internalDispatch()
                                                                                      at com.remobjects.sdk.AsyncRequest.run()
```

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [November 17, 2017, 9:40am UTC](https://talk.remobjects.com/t/android-session-timeout/14834/6 "2017-11-17T09:40:59Z")

</div>

Thanks, logged as bugs://79029

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [November 17, 2017, 2:53pm UTC](https://talk.remobjects.com/t/android-session-timeout/14834/7 "2017-11-17T14:53:14Z")

</div>

bugs://79029 got closed with status fixed.

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [November 17, 2017, 2:54pm UTC](https://talk.remobjects.com/t/android-session-timeout/14834/8 "2017-11-17T14:54:20Z")

</div>

Thanks for the testcase. The issue has been reproduced and fixed. The fix will be available in the next Beta build.
