Using the same socket in different/multiple threads, possible? how?

Login to reply to this topic.
Fri, 2006-01-13 11:17
Joined: 2006-01-13
Forum posts: 1
My program creates two threads: one thread sends data, another thread receives data.

Is it possible to:

  • Create a socket in the main thread and use it in anther thread?
  • Use the same socket in both the sending and the receiving thread?

The reason I want to use the same socket for both sending and receiving is that I want the sending and receiving socket to use the same source port.

I did find out the RSocketServ can be used in multiple threads (using the ShareAuto() method), but what use is sharing the RSocketServ when you can't share the sockets themselves?

Sun, 2006-01-22 16:30
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 723
Re: Using the same socket in different/multiple threads, possibl
You don't have to have two threads just for that purpose. Sharing a socket for reading and writing works in the same thread.

In addition, you're really discouraged to use threads in such a scenario: you should rather get familiar with active objects, a "replacement" of threads, instead. Okay, threads still can be used, but active objects is really the preferred solution in Symbian OS.

Tote

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

Wed, 2007-02-21 11:35
Joined: 2005-02-14
Forum posts: 19
Re: Using the same socket in different/multiple threads, possibl

Quote
UIQ 3 SDK » Symbian OS v9.1 » Symbian OS guide » System libraries » Using C Standard Library (STDLIB) » Design and implementation of STDLIB

Symbian OS resources such as RFiles and RSockets are derived from class RSubSessionBase, so are thread specific. This means they cannot be used by any thread other than the one which opened them.

In an application where RSockets are created and used in different threads, we do see that our application works fine on the emulator .. Is it that the RSocket objects are not shared only on the device ? Huh

Are there any workarounds in the case that we are forced to use them in different threads?

Thanks,
Tanuja
Wed, 2007-02-21 13:57
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 723
Re: Using the same socket in different/multiple threads, possibl
Dunno. However, our solution in which we shared an RFile handle between two threads did not work.  Shocked

Tote

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

  • Login to reply to this topic.