Solved

Opening windows in perl

Posted on 1998-07-26
24
165 Views
Last Modified: 2013-12-25
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
Comment
Question by:freak022398
  • 11
  • 8
  • 5
24 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1831188
Is there a way to pop up a window on your local server without perl?
0
 

Author Comment

by:freak022398
ID: 1831189
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
 
LVL 84

Expert Comment

by:ozo
ID: 1831190
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
 

Author Comment

by:freak022398
ID: 1831191
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
 
LVL 84

Expert Comment

by:ozo
ID: 1831192
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
 

Author Comment

by:freak022398
ID: 1831193
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
 
LVL 6

Expert Comment

by:alamo
ID: 1831194
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
 

Author Comment

by:freak022398
ID: 1831195
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
 
LVL 84

Expert Comment

by:ozo
ID: 1831196
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
 
LVL 6

Expert Comment

by:alamo
ID: 1831197
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
 

Author Comment

by:freak022398
ID: 1831198
I'll do that, or maybe alamo can help?

Martin.

0
 

Author Comment

by:freak022398
ID: 1831199
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 6

Expert Comment

by:alamo
ID: 1831200
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
 

Author Comment

by:freak022398
ID: 1831201
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
 
LVL 84

Expert Comment

by:ozo
ID: 1831202
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
 

Author Comment

by:freak022398
ID: 1831203
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
 
LVL 6

Expert Comment

by:alamo
ID: 1831204
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
 
LVL 6

Expert Comment

by:alamo
ID: 1831205
Oops, forgot a critical item - on the Winsock1 control you need to set the Protocol property to 1 (sckUDPProtocol).
0
 

Author Comment

by:freak022398
ID: 1831206
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
 
LVL 6

Expert Comment

by:alamo
ID: 1831207
So MArtin, had  a chance to tets this yet? Should I post an answer?
0
 
LVL 6

Accepted Solution

by:
alamo earned 80 total points
ID: 1831208
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
 

Author Comment

by:freak022398
ID: 1831209
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
 

Author Comment

by:freak022398
ID: 1831210
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
 
LVL 6

Expert Comment

by:alamo
ID: 1831211
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now