Results 1 to 2 of 2
  1. #1
    flok is offline Member
    Join Date
    Sep 2009
    Gouda, the Netherlands
    Rep Power

    Default concurrent access to a Socket()


    Can one do a read on a socket while an other thread does a write in the same time on the same socket?

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    San Jose, CA, USA
    Rep Power


    Yes you can. Though i would be careful not to write with two threads at the same time if you message is split up into multiple parts. I put a lock on the write stream before i use it.

    Java Code:
    synchronized(output) //lock the object
       //write to the output stream
    My Hobby Project: LegacyClone

Similar Threads

  1. Concurrent trail example
    By bert682 in forum Threads and Synchronization
    Replies: 4
    Last Post: 10-11-2009, 05:47 PM
  2. RCU in Java? or some list/set/etc. which can handle concurrent access?
    By flok in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-14-2009, 11:59 PM
  3. append response to the request from Socket and write to another socket
    By in forum Networking
    Replies: 3
    Last Post: 04-17-2009, 08:02 PM
  4. FileLock and file access from concurrent threads..
    By fxRichard in forum Advanced Java
    Replies: 5
    Last Post: 01-02-2009, 09:08 PM
  5. Concurrent Applications
    By m@tqi in forum Advanced Java
    Replies: 1
    Last Post: 12-01-2007, 01:09 AM

Posting Permissions

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