This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-01-24 19:50:05

BenderLover
Scratcher
Registered: 2010-01-23
Posts: 1

remote sensor protocoll, perl

Hi

Does someone have examples for sending/reciewing Messages with perl?

The Python-Scripts from wiki do work, so my setup should be ok.

Only I didn't get it working... I just used basic examples of IO::SOCKET::INET, like this:
----
use IO::Socket::INET;

# Create a new socket
$MySocket=new IO::Socket::INET->new(LocalPort=>42001,Proto=>'tcp');

# Keep receiving messages from client
$def_msg="\nReceiving message from client.....\n";
while(1)
{   
    $MySocket->recv($text,1024);
    if($text ne '')
    {   
        print "\nReceived message '", $text,"'\n";
    }
    # If client message is empty exit
    else
    {   
        print "Cilent has exited!";
        exit 1;
    }
}
---

I supose I missed some options, as it does not work...

Thanks

BenderLover

Last edited by BenderLover (2010-01-24 19:50:51)

Offline

 

#2 2010-01-27 15:29:02

chalkmarrow
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: remote sensor protocoll, perl

I don't know much about perl, but I think that you have to specify the host address. Since it is a client, I think you need to specify Proto, PeerAddr, and PeerPort. Maybe something like this (based on a simple example I saw in some docs):

#!/usr/bin/perl -w
    use IO::Socket;
    $remote = IO::Socket::INET->new(
                        Proto    => "tcp",
                        PeerAddr => "localhost",
                        PeerPort => "42001",
                    )
                  or die "cannot connect to port at localhost";
    while ( <$remote> ) { print }

Last edited by chalkmarrow (2010-01-27 17:38:17)

Offline

 

Board footer