×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    9

    Question Query regarding Sockets and Threads.

    Hi,

    From what I heard and tried myself, sockets are not sharable between threads. Sockets opened in one thread cannot be used by another thread in the same process.

    But how come we can do this using OpenC/C++. I was able to do this using OpenC/C++.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: Query regarding Sockets and Threads.

    According to some discussions RSessionBase::ShareAuto invoked on RSocketServ solves the threading issue. And also note that OpenC is a rather big framework actually, thus it may easily contain other means for supporting threaded access to sockets, and anything else.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    9

    Question Re: Query regarding Sockets and Threads.

    Does ShareAuto allows sockets to be shared or just the session?

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: Query regarding Sockets and Threads.

    As far as I know, yes, it does.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    9

    Thumbs up Re: Query regarding Sockets and Threads.

    Hi,

    I tried using the ShareAuto function and now it seems to work. I'm making the main thread to send data to a socket(with localhost ip : 127.0.0.1) at a regular interval(using an AO) and listening to the same socket using another thread. The only problem I'm facing is when I create the new thread and starts executing, the main thread goes on hold. I dont see any data being sent to the port until i press the options softkey(the options menu gets shown and in the background i can see the read and write working).. I'm not sure why.

    Maybe i'll integrate it with my main app(I'm doing this right now using OpenC) and see how it works..

    Thanks for the help, Wizard..

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: Query regarding Sockets and Threads.

    If opening the menu helps, it means that something is wrong with your AO implementation:
    - make sure that you are not declaring an own TRequestStatus member variable
    - make sure that you invoke SetActive when passing iStatus to RSocket::Something
    - make sure that you do not invoke SetActive without passing iStatus to someone
    - make sure that you have added the AO to the Active Scheduler (CActiveScheduler::Add)

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    9

    Question Re: Query regarding Sockets and Threads.

    Hi wizard,

    I have implemented the AO on my main thread and am using RTimer for sending the data after a fixed interval. And I'm following the AO implementation tips.

    On the listening thread(which I create), I just listen at the port and I wait until i get data. I dont use any AO here.. I make this call a blocking call by using User::WaitForRequest. I was trying to complete the proof quickly, I accidently added an extra User::WaitForRequest which made my main thread to suspend.. It started working fine when I removed that. But isnt this strange? WaitForRequest shouldnt have any problem if the TRequestStatus object's value is KErrNone.

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: Query regarding Sockets and Threads.

    User::WaitForRequest does not have any problems, it simply waits for something to happen:
    - it is not enough if the TRequestStatus is set to anything else than KRequestPending
    - the request semaphore of the given thread also has to be triggered.
    Practically when you open the menu, you are stealing an event from the Windows Server.

    This is the difference between
    Code:
    TRequestStatus status=KErrNone
    and
    Code:
    TRequestStatus status;
    TRequestStatus *statusptr;
    User::RequestComplete(statusptr,KErrNone);
    the latter also triggers the request semaphore.

Similar Threads

  1. HTTP Tunnel feasability : sockets, threads
    By nono240 in forum Python
    Replies: 2
    Last Post: 2008-02-25, 16:07
  2. Using the same socket in different/multiple threads, possible?
    By pandakopanda in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2008-02-07, 19:17
  3. sockets with multiply threads problem
    By shadow-2005 in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2007-12-05, 07:47
  4. mixing AO, threads and sockets
    By mikfi in forum Symbian Networking & Messaging (Closed)
    Replies: 6
    Last Post: 2006-11-21, 23:19
  5. libc sockets read problem
    By cinnet in forum Symbian C++
    Replies: 0
    Last Post: 2005-11-25, 14:19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •