Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8018097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:02:40+00:00 2026-06-04T21:02:40+00:00

I have to write simple client-server application that uses Unix datagram socket. Client may

  • 0

I have to write simple client-server application that uses Unix datagram socket. Client may send information to server on the request from the server or he may receive information from server on the request from himself.

I have an idea that one thread will be waiting for user input that determines what request we want to send to the server, and the other thread will just wait for message on the socket from the server, if it is the message we requested it will write it to standard output, if it is the server request thread would write what server requested. I would use mutex so the two threads won’t write at the same time to the same socket.

My question is, how the sockets will behave if one thread will read from some socket and at the same time other thread will be sending data using the same socket, is it safe? Or should I use mutex for this situation also?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:02:42+00:00Added an answer on June 4, 2026 at 9:02 pm

    Kernel structures are normally built in a thread-safe way; and sockets are no exception.
    If you should be worried about anything, it isn’t the safety of using sockets and threads but the logic of your program.

    Also, I’d like to mention that stream sockets are full-duplex, meaning read/write are guaranteed happen simultaneously safely, how can this be happen? Kernel locks for you or makes sure you can do both send and receive at the same time.

    For the full-duplex argument:
    http://www.kernel.org/doc/man-pages/online/pages/man2/socket.2.html
    For the kernel structures are thread safe:
    I couldn’t find you a link to support this, but I am 99% sure about it.

    P.S When in doubt, testing the thing might help
    EDIT:

    Please, if something of what I said is wrong, comment about it before down voting.

    EDIT.2 :
    Here you can find that ths POSIX standard specifies that all of its functions have to be thread-safe except a list defined in section 2.9.1
    http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a simple server application that will take commands from a
I have to write a simple mobile application that is able to receive broadcast
I have started to write a Python 3.x client application. The server application exists
I'm writing a simple web app in PHP that needs to have write access
I have to write a program that sniffs network packets (part1-the simple part). And
I'm trying to write a simple application where I have a keyboard listener in
I'm looking to write a simple proxy server in .NET. Does anyone have any
I have designed a stylesheet/javascript files bundler and minifier that uses a simple cache
I have an existing REST application on my server. For example, if you send
I have two utilities written in C++, TCP/IP server and client that I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.