LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-27-2020, 06:07 PM   #1
linxbee
Member
 
Registered: Jan 2020
Distribution: RHEL,CENTOS, Ubuntu
Posts: 52

Rep: Reputation: Disabled
Which IPC is better for message exchange


I am working on a problem where I need to pass a message from one thread to other, for example I have 3 threads one for each player, each player has to send 2 messages to other players. Other players also need give their acceptance or rejection based on message they receive.

Please advice which IPC is better for this scenario?
 
Old 01-27-2020, 08:11 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by linxbee View Post
thread

IPC
Are we talking about processes or threads?
 
1 members found this post helpful.
Old 01-28-2020, 01:08 AM   #3
linxbee
Member
 
Registered: Jan 2020
Distribution: RHEL,CENTOS, Ubuntu
Posts: 52

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
Are we talking about processes or threads?
I am planning to use threads
 
Old 01-28-2020, 08:00 AM   #4
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
You need to define some parameters. Does each player have a thread that is blocking on the message queue? Are the messages to be kept "secret" from other players? Are messages contemporaneous or is a mailbox adequate (read and respond at some interval)?

It's possible you don't need IPC - since it is internal to a signal thread, managing data structures might work just as well.
 
Old 01-28-2020, 10:12 AM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Just use globals. Protect them with mutexes when threads are writing to them.

BTW, "IPC" is between processes, not threads. You might want to look up what it stands for.

Last edited by dugan; 01-28-2020 at 10:27 PM.
 
Old 01-28-2020, 10:19 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
You can use any or all of the IPC mechanisms you want. I submit that it really depends what message you need to convey. For instance if it is related to the processes or threads, you can use a signal. You can use a pipe, you can use sockets, both of those will convey greater information than singular information. You also can use memory protected by a mutex, as stated earlier in the replies.

There may be a "best" for your situation, but you'll need to determine which of these conveyances works best for your program architecture.
 
Old 01-28-2020, 10:25 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
I've recently tried a multi-threaded process where messages are forwarded on pipes (pipe(2)), and a message is always an address of the actual data-area.
 
Old 01-29-2020, 12:35 AM   #8
linxbee
Member
 
Registered: Jan 2020
Distribution: RHEL,CENTOS, Ubuntu
Posts: 52

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by SoftSprocket View Post
You need to define some parameters. Does each player have a thread that is blocking on the message queue? Are the messages to be kept "secret" from other players? Are messages contemporaneous or is a mailbox adequate (read and respond at some interval)?

It's possible you don't need IPC - since it is internal to a signal thread, managing data structures might work just as well.
Every player should have a way to send & receiver message, as soon as the message arrives player should pick up, each player is unware of other players, but, should have a way to send/receive message.

I guess, I would prefer sockets, because currently I am working on a standalone game , but later it might be an online game.

correct me if I am wrong.., there is no other IPC which communicates through network other than sockets right?
so better use sockets only even if it is a standalone, so that we can improve latter point of for online?

Last edited by linxbee; 01-29-2020 at 12:38 AM. Reason: added question
 
Old 01-29-2020, 07:23 AM   #9
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
Quote:
Originally Posted by linxbee View Post

correct me if I am wrong.., there is no other IPC which communicates through network other than sockets right?
so better use sockets only even if it is a standalone, so that we can improve latter point of for online?
There has been other interfaces other then sockets but Berkley (POSIX) Sockets has supplanted them.

You should at least abstract your communication modules so they can be easily swapped out if you want to try something other then sockets. There are a variety of flavors and options to consider so even if you use sockets abstracting your communication methods is a good idea.
 
Old 01-29-2020, 10:18 AM   #10
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
I wouldn't suggest using threads that run on different computers. Actually, they shouldn't called 'threads' to begin with.
 
Old 01-29-2020, 11:21 AM   #11
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
If we're talking about multiple executable programs, then I'm not sure if you're using the word "threads" correctly.
 
1 members found this post helpful.
Old 01-29-2020, 11:21 AM   #12
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
If we're talking about multiple executable programs, then I'm not sure if you're using the word "threads" correctly.
 
1 members found this post helpful.
Old 01-29-2020, 12:38 PM   #13
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
So I think the question basically is client-server vs peer-to-peer networking.
 
Old 01-29-2020, 05:55 PM   #14
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by NevemTeve View Post
I wouldn't suggest using threads that run on different computers. Actually, they shouldn't called 'threads' to begin with.
Quote:
Originally Posted by dugan View Post
If we're talking about multiple executable programs, then I'm not sure if you're using the word "threads" correctly.
Quote:
Originally Posted by NevemTeve View Post
So I think the question basically is client-server vs peer-to-peer networking.
Agreed on all points.

While it seems subtle, I think it would be beneficial to recognize the difference here and that IPC, to me, is defined as InterProcess Communications. Sockets is available, but that really means "local sockets".

And I do feel you have an answer for this question.
 
Old 01-29-2020, 09:24 PM   #15
linxbee
Member
 
Registered: Jan 2020
Distribution: RHEL,CENTOS, Ubuntu
Posts: 52

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by SoftSprocket View Post
There has been other interfaces other then sockets but Berkley (POSIX) Sockets has supplanted them.

You should at least abstract your communication modules so they can be easily swapped out if you want to try something other then sockets. There are a variety of flavors and options to consider so even if you use sockets abstracting your communication methods is a good idea.

Thanks, This is a good suggestion
 
Old 01-30-2020, 06:22 AM   #16
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239

Use the network, TCP or UDP sockets.

It will work locally or distributed.
It will scale from a desktop PC to the entire universe.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is better for embedded Linux ipc: message queue vs socket david_8274 Linux - Newbie 3 03-11-2016 05:30 PM
How to Relay mail back to Exchange if an Exchange mailbox exists in Exchange aalger Linux - Networking 6 03-11-2015 12:25 PM
IPC message between process (Sync) davidho3 Linux - Networking 1 07-24-2004 08:20 AM
IPC message between process (Sync) davidho3 Programming 1 07-24-2004 07:37 AM
IPC (Message Queues vs. FIFOs vs. Unix-domain Sockets) TedMaul Programming 0 03-18-2004 04:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration