Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Opening windows in perl

I wouldt like to make a perl script that allows users of my
server to send me small messages, that shouldt pop up in a
window on my local screen, not the user that send the message.

Can this be done, and how?

CYA. Martin.
0
freak022398
Asked:
freak022398
  • 11
  • 8
  • 5
1 Solution
 
ozoCommented:
Is there a way to pop up a window on your local server without perl?
0
 
freak022398Author Commented:
My server is running under Win95, so i guess not! (If there is, i don't know how)

Maybe i couldt start by opening a window manualy. And then find some way to get my perl script to output it's messages to that window.

CYA. Martin.

0
 
ozoCommented:
How about a program running in that window that continuously reads from a file,
and a perl script that writes messages to that file?
0
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
freak022398Author Commented:
Would'nt they collide, i mean while perl want to write, the other prog may want to read at the same time!

Is there a way for perl to signal the other prog?

CYA. Martin.

0
 
ozoCommented:
reading and writing at the same time shouldn't be as much of a problem
as two processes writing at the same time.
But in either case, flock is the function designed to deal with avoiding colisions.

kill is the function used for sending signals.
0
 
freak022398Author Commented:
Can you give me an example on how i signal anoher process? (I think it's going to be a Visual Basic program doing the display part)

Martin.

0
 
alamoCommented:
Just an idea: I am not sure how the "best" way to do this might be, but I'd probably do it as a perl CGI script communicating with a VB5 program via a TCP/IP socket. Both programming environments can do sockets pretty easily, and communicating through shared files very rarely "feels right" to me, though I know a lot of people like the method.
0
 
freak022398Author Commented:
I don't normaly like the file solution either, but this is only going to be a temporarily solution until i get the time to figure out how to do it probably. And i'm afraid that TCP/IP communication is a bit to hard for me at the moment (I've only been working on this server for 2 months now, and before that i allmost didnt know that perl existed) So i have to go for the easiest (fastest) solution.

Martin.

0
 
ozoCommented:
I agree that sockets would be nicer if your Visual Basic program supports that.
I can't help you with that end though.  You may want to ask in the Visual Basic topic area.
0
 
alamoCommented:
Martin, do you have VB5? VB5 has a Winsock control which makes sockets relatively easy. If you have VB4 or earlier then forget sockets, too tough.
0
 
freak022398Author Commented:
I'll do that, or maybe alamo can help?

Martin.

0
 
freak022398Author Commented:
I do have VB5. But i'm going to need a lot of help on the socket part as i dont know VB very well. But a friend of mine does, and he says it's a real pain to get sockets to work, or is he wrong?
(Is there any examples on socket controls with VB5?)

Martin.
0
 
alamoCommented:
My experience with sockets in VB5 is that it is much easier in theory than in practice, due to the idiosyncracies of the Winsock control (probably due to Microsoft not really understanding TCP/IP because it didn't invent it). But this seems to me to be a very simple application, for that matter it could almost use a UDP datagram instead of a full-blown socket connection.

I have been doing VB 6 years longer than I've been doing Perl, so I should be able to figure out how to do something like this pretty easily. Give me, if you will, a little time to look at this.
0
 
freak022398Author Commented:
Fine, take you'r time, you will probably solve it before me, no matter how long you take :)
But how long do you need? (I mean, do i grade you now, or later?)

Martin.
0
 
ozoCommented:
Or you could write both ends of the socket in Perl.
(what should the message send program do if the window program isn't running?
should it queue up the message?
If you already have a program that pops up email messages, you might just have the sending progam mail you the message...)
0
 
freak022398Author Commented:
That was an allmost perfect solution, except that i would like to see the message the second it gets in, and my mail is only checked every 5 minute to avoid using to much bandwidth, (my server is a 75MHz pentium, so i need all the speed i can get out of it!)

So i guess i have to do it the file way until i (or someone else, alamo?) finds a better solution. Something nice would be a simple way for VB5 and perl to talk to each other, but i guess thats impossible!

Martin.
0
 
alamoCommented:
As to grading - you can't do it until I or someone else posts asan "answer" rather than a comment, and unlike the other questions I answered for you where your question was precise and the answer clear, I won't post an answer until you see the code work and agree it will fulfill your needs.

Here's a simple proof-of-concept:

Perl script to send a UDP message to the same machine's port 9000:

use Socket;
$iaddr = gethostbyname("localhost");
$proto = getprotobyname('udp');
$paddr = sockaddr_in(0, $iaddr); # 0 means let kernel pick
socket(SOCKET, PF_INET, SOCK_DGRAM, $proto)   || die "socket: $!";
bind(SOCKET, $paddr)                          || die "bind: $!";

$hisiaddr = inet_aton("localhost")    || die "unknown host";
$hispaddr = sockaddr_in(9000, $hisiaddr);
$message = "this is a test";
defined(send(SOCKET, $message, 0, $hispaddr))    || die "send $host: $!";

As to VB: here's a simple VB program to listen to port 9000:

Take a form, add a textbox (text1) and a winsock control (Winsock1). (If the winsock control doesn't show in your tool palette, press Ctrl+T and add it). Add the following code:

Private Sub Form_Load()
    Winsock1.Bind 9000
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim str As String
    Winsock1.GetData str
    Text1.Text = str
    MsgBox "New Message Arrived", , "Alerter"
End Sub

Now run the VB program, then run the perl script and the VB program should place the message into the textbox and pop up a message.
0
 
alamoCommented:
Oops, forgot a critical item - on the Winsock1 control you need to set the Protocol property to 1 (sckUDPProtocol).
0
 
freak022398Author Commented:
Looks fine, i'll look at it later today as it's getting very close to the time i'm going to sleep. (I've had about 6 hours of sleep the last 61 hours and 41 minutes, and the server has only had one single crash, last weekend we had about 30!)

So i guess i'm just going to pull the plug for the server until next friday (weekends only, dynamic ip!)

I'll let you know when i have looked at the code. (Sometime later today, or tonight)

CYA. Martin.


0
 
alamoCommented:
So MArtin, had  a chance to tets this yet? Should I post an answer?
0
 
alamoCommented:
Since it looks like you need some time to test this, and since I am pretty sure the sample I posted will do what you want, I am posting this as an answer. Let me know how it goes!
0
 
freak022398Author Commented:
Hi there, I am answering for Martin, he is unavailable at the moment, and will be ... some time, this is probably going to be in slowmotion, as I am to snail between Martin and the system here.

Hope you can await an answer till later the comming week.
Regards, on the way of Martin.
/Jacob
0
 
freak022398Author Commented:
Hi Alamo. I'm back again :) you were right, it was what i needed! Thank you for the, and sorry for the delay :)

CYA. Martin.

0
 
alamoCommented:
The delay's no problem at all unless it gets so long that the question gets autograded, I was glad I was able to help!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 11
  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now