• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

MultiThreading and sockets

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible for multiple threads to access the same socket descriptor,to send different messages, without any synchronization issues??

The messages are sent over TCP/IP.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd want a "synchronized" clause around any reads or writes to make sure you send a complete message or receive a complete message with no interferance from other threads. You're kinda doing your own multiplexing. It will be an interesting server on the other end that can figure out the inbound messages!
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try to create a queue and queue reader that sends data over the sockets. The other threads will put messages on that queue.
 
Priya Vasudevan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Yaroslav Chinskiy:
You can try to create a queue and queue reader that sends data over the sockets. The other threads will put messages on that queue.



Multiple threads on the client side need to establish connection to different servers.If thread T1 needs to send data to IP1 and thread T2 also needs to send data to IP1, T2 needs to wait for the socket descriptor to get free.
Would it improve performance by opening multiple socket descriptors for each Thread,on the client end, so that simultaneously messages can be sent??
 
this is supposed to be a surprise, but it smells like a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic