Showing posts with label session-state. Show all posts
Showing posts with label session-state. Show all posts

Monday, April 25, 2016

How to maintain clock session between two different devices?

Leave a Comment

I am working on iOS application which requires to maintain a clock timer session between two devices upon acceptance of both device users?

But I am not sure how this can be achieved without getting a flaw in timing on both devices?

I have already look on following ideas:

1)Maintain state of both devices with help of Webservices or push notification so that timer on both devices will start at the same time. But if network is not working properly this approach is getting failed and there is flaw in timer on both devices.

In addition, I also want to know how can I prevent application clock remain unchanged even after changing device date and time.

Any help over this would be appreciated.

Thanks in advance.

3 Answers

Answers 1

You can use ios-ntp to get network time and calculate time offset between local and network time on both devices. When you start timer on one device, you subtract the offset from the local timestamp and send the resulting network timestamp to another device. On another device you append the local offset to the network timestamp and get the timestamp of timer start in the local time.

You can use UIApplicationDelegate.applicationSignificantTimeChange(_ application: UIApplication) to monitor time changes on the device and recalculate the offset by updating network time.

Answers 2

Some thoughts:

  • keep track of your own time, be independent of the system clock. Only use the system clock to convert your time to user-wall-clock time when you need to display something.

  • a time-unit (like a second) on one device should equal a second on the other device, e.g. trust that the duration of it is equal on both devices)

  • network delay is a fundamental problem. Consider that there might always be an offset between the two devices. Maybe you can come up with a way that reveals the lag, or you could come up with a way where the absolute time is not relevant

Here is an idea: when device1 sends a sync-packet every 5 seconds, device2 should have this packet before it does whatever happens at second 6. So if the packet is not there yet in device2 at 5 seconds, it could wait for the packet to arrive before it continues to do whatever needs to be done next. When the packet arrives at 3 seconds, device2 should hold on to it and process it at second 5. Do this in a bi-directional way, and both apps are in sync within a 5 seconds time-frame. Depending on your requirements and the network, you have to decide what 'waiting' means and how often to send a sync-packet.

Answers 3

You can achieve by the webservice in which you just send flag to global clock,In this you just set flag for start and end time so by using this method you can easily synchronize the time between two ro more devices.

Read More

Monday, April 11, 2016

Custom MySQL session store provider - deserialization issue

Leave a Comment

I have migrated my project from MSSQL to MySQL and one of the feature I have to implement is a possibility to store sessions on db side, hence custom session store provider has to be configured. I used MySQL connector for visual studio to properly setup session provider. Here is a snippet from my web.config:

<connectionStrings> <remove name="LocalMySqlServer" /> <add name="LocalMySqlServer" connectionString="server=<SERVER>;user=<USER>;pwd=<PASSWORD>;port=<PORT>;database=<DBNAME>;AutoEnlist=false;" providerName="MySql.Data.MySqlClient" /> </connectionStrings>   <system.web>  <sessionState mode="Custom" cookieless="false" timeout="20" allowCustomSqlDatabase="true"  regenerateExpiredSessionId="true" customProvider="MySqlSessionStateProvider">   <providers>     <clear/>     <add name="MySqlSessionStateProvider" type="MySql.Web.SessionState.MySqlSessionStateStore, MySql.Web, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="My Local Session State" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" enableExpireCallback="False" />   </providers> </sessionState> ... </system.web> 

Once I run my application db schema was modified and all required tables were created:

enter image description here

Furthermore, I detected that during execution session table is filling by session info so I it is a good signal that connection works and MySQL custom provider is doing what is supposed to do.

enter image description here

Unfortunately, after some time my application fails due to System.OutOfMemoryException. The stack trace looks like:

enter image description here

My assumption is that there is some problem with session items deserialization. I have a few classes which are stored in a session and all of them are marked by appropriate [Serializable] attribute. Other items has primitive types (bool, int..) So, my question is what else could cause this issue? The problem is that I even can't detect exact place from where this issue is firing. Any suggestion are appreciated.

1 Answers

Answers 1

Can you please recheck that all items inside your classes are public [ private members would not be taken care of during serialization].

Read More