Results 1 to 2 of 2
  1. #1
    shamael is offline Member
    Join Date
    Jul 2009
    Posts
    3
    Rep Power
    0

    Question Can I pass sockets to different threads?

    Hallo, I am writing a client/server program and I am having troubles passing sockets among classes.
    Basically, the client connects to a login manager, which checks credentials and then passes the socket to another class for further communication.
    If i close the DataInputStream and the DataOutputStream, I get a "socket closed" exception when i try to open new ones in the "other" class (although I did not close the socket itself), whereas if I do not close the streams, I get a EOFException. :confused:
    Maybe my login thread closes the socket when it dies, even though that socket is referenced in another thread?
    I am starting to think that it is not possible to achieve what I was trying to do and that I'd need to open a new socket, but I'd rather not if possible so please let me know if it can be done...

  2. #2
    shamael is offline Member
    Join Date
    Jul 2009
    Posts
    3
    Rep Power
    0

    Default

    Actually I had overlooked a couple of close() in the client...
    So that part works now, simply passing the reference of the socket does it.

Similar Threads

  1. Sockets NIO
    By aamp in forum New To Java
    Replies: 3
    Last Post: 01-15-2009, 11:56 AM
  2. Threads + Sockets
    By Tomdarkness in forum New To Java
    Replies: 1
    Last Post: 12-24-2008, 01:06 AM
  3. Sockets
    By Zosden in forum Networking
    Replies: 16
    Last Post: 05-27-2008, 05:55 PM
  4. Help with Sockets
    By Eric in forum Networking
    Replies: 3
    Last Post: 12-01-2007, 09:09 PM

Tags for this Thread

Posting Permissions

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