Alternative network messaging?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Alternative network messaging?
# 15  
Old 10-24-2012
I would like to implement a push service, but I havent't found any example for that on the internet yet. The step from "kill" command to push service is too large for me.
# 16  
Old 10-25-2012
A signal is a way to tell a program to do something when told instead of constantly checking for something. If it hasn't been told to do anything when it gets the signal, the signal will probably kill it instead.

Code:
#!/bin/sh

# Display the contents of a file and set a variable on SIGINT
trap 'cat /tmp/filename ; rm /tmp/filename ; VAR=1' INT

echo "My PID is $$"

while true
do
        VAR=0
        # Two reason read might fail -- end of file, or SIGINT.
        # If it was interrupted, just try again.  Otherwise, quit.
        if ! read LINE
        then
                [ "$VAR" -eq 1 ] && continue
                break
        fi

        echo "read line from keyboard: $LINE"
done

Run this in one window:
Code:
$ ./stupidchat.sh

My pid is 21188

Then do this in another:

Code:
# Vitally important message
$ echo "hey guys alj af MY FACE IS A ROTTORN BANANA" >/tmp/filename
$ kill -INT 21188

...and the first script should receive the signal, trap it, read the file and delete it

Last edited by Corona688; 10-25-2012 at 01:09 PM..
This User Gave Thanks to Corona688 For This Post:
# 17  
Old 10-25-2012
Thanks for your example :-)
There is still a problem, because I can't call "kill" on a remote machine. Hence, I can only call a remote script that sends the signal to the remote process. Is It better to call the process by name or by process ID? Will the process ID be constant after reboot?
# 18  
Old 10-25-2012
Yes, kill is named for it's most popular use, termination, but it is just a signal sender.

in shell, trap is the shell signal catcher. SIGINT was available, but for apps SIGUSR1 and SIGUSR2 are most appropriate: Man Page for signal (linux Section 7) - The UNIX and Linux Forums

The signal processing is done out of sequence with the process thread(s), but in the same process so variables are passed.

So, you can push files to input-dir/unique.take-me-extension, the final step being mv and then kill to start the possibly, usually sleeping server so it processes the input.(
Code:
ssh server_host 'cat >input-dir/unique.take-me-extension.tmp
  mv input-dir/unique.take-me-extension.tmp input-dir/unique.take-me-extension
  kill -SIGUSR1 `< server-pid-file`
 ' < input-file

Of course, you have to be the same id or root to signal a process. Named pipes can stall servers that only require the writer have permission on the pipe.
Code:
$ mknod p p
$ ls -lA|grep '^p'
prw-r--r--   1 my_uid    my_group          0 Oct 25 14:54 p
$ while :
do
 cat <p
done &
[1]     19299
$ echo hi >p
$ hi
echo hello >p
$ hello


Last edited by DGPickett; 10-25-2012 at 04:01 PM..
This User Gave Thanks to DGPickett For This Post:
# 19  
Old 10-25-2012
Quote:
Originally Posted by 123_abc
Is It better to call the process by name or by process ID?
There may be a hundred scripts running with the same name, but they will all have different process ID's.
Quote:
Will the process ID be constant after reboot?
No. The usual procedure is for a process to save a file under /var/run/ somewhere containing its process ID for other things to check.
This User Gave Thanks to Corona688 For This Post:
# 20  
Old 10-30-2012
The whole app shall be some kind of LAN messaging program with a central host that receives, stores and forwards messages to the correct receiver when he is online. For sending messages over the LAN, rcp shall be used.

On the mediator host, each user has a folder where all the messages are stored that are addressed to him. Therefore, each sender must be able to send a signal to this mediator host when a message has been sent. I haven't yet completely understood how to call unambiguously a process on this host.

Last edited by 123_abc; 10-30-2012 at 02:35 PM.. Reason: additional thought
# 21  
Old 10-30-2012
A common dir means there is only one place to look when woken up to process input. The file name itself can contain unique information like what user sent it and what the sequence number is. A "kill -SIGUSR1 `<pid_file`" can wake up the service.

If you make it a UDP service, the server blocks on the UDP socket waiting for incoming messages, processing them one at a time. They can be queued in the socket buffer, which can be made large enough to deal with the probalbe backlog. The process reading the socket can just log the messages for further processing, so there is no liklihood of a big backlog. The service can frame the bytes in the log into different discussions. Once the log gets to a certain size, it can be rotated out for another. The log could even be a zip file for the day, with each message an archived file in appropriate interanl folder paths. You can glob through zip files as if they were directories with some tools like MS Windows Compressed folders and HXTT JDBC CSV/Text Drivers. UDP also allows for a multicast of messages back to participating users. The size is a bit restricted, not as much as twitter, 65k, but 1,440 is a more reliable size.
This User Gave Thanks to DGPickett For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

The DT messaging system could not be started.

Good Morning, Users can no longer log into SunBlade 2500 Solaris 9 system (though root still can). Here's what I'm getting and what I've done. I'm most suspicious of the full drive since that pops up twice and I did see one looks full. What's a good way to reduce what's on it?- or.. what else... (2 Replies)
Discussion started by: Stellaman1977
2 Replies

2. UNIX for Advanced & Expert Users

The DT messaging system could not be started

Hello All, I am getting " The DT messaging system could not be started" message when wants to login as root on a box running on tru64 5.1A. /etc/hosts is ok. when i see in .dt/errorlog it shows message server could not be started. Thanks for help. Awadhesh (2 Replies)
Discussion started by: Awadhesh
2 Replies

3. Programming

problems while using messaging queues....

hi I am using posix functions such as mq_open, mq_close and including the mqueue.h. but its giving a linking error,"undefined reference to mq_open and mq_close". it it that we have to link some library or so while compiling... plzzz help Thanxs Mohit (0 Replies)
Discussion started by: mohit3884
0 Replies

4. UNIX and Linux Applications

how do i enable messaging

hi guyz i work as a system administrator for some organization(am a newbie). one of the solaris machines is loaded with the messenger server...all configured by a former administrator. my task was to create user accounts for the mail and calendar services and as i checked its not working .....i... (0 Replies)
Discussion started by: henokia4j
0 Replies

5. IP Networking

DT messaging could not be started

this id the message i get with a suggestions to check those files: /etc/src.sh /etc/hosts /usr/adm/inetd.sec i have little knowledge of hoe to edit those files/ i went to the etc library and didn't found src.sh file. what should i do? also didn't find the inetd.sec file In the host... (3 Replies)
Discussion started by: amirp
3 Replies

6. Programming

Instant Messaging App Help

I was hoping someone could assist me on a text-based instant messaging client(using UDP) I am working on. I have the network communication basics already in place but, specifically, needed some further help on the "messaging other users" and "getting a user list" functions. The server code that... (0 Replies)
Discussion started by: AusTex
0 Replies
Login or Register to Ask a Question