Re: Perl Socket Client for C++ Server

2005-04-07 Thread Jay Savage
On Apr 7, 2005 2:00 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi Jay,
> 
> thanks for the answer.
> 
> > Firt things first.  Why did you comment out use strict?  That's never
> > a good sign.  also, loading both IO::Socket::Unix and Socket probably
> > isn't the best idea.  the main problem here, though would seem to be
> > mixing your syntax.  You're calling the object-oriented IO::Socket
> > interface, but you're using it like you would the builtin functions.
> > You're also using incorect argument names.
> Your right. It was a dirty hack, and because it did not work with
> IO::Socket::Unix, i tried the Socket library.
> 
> i'm playing with your version
> (http://www.honktown.de/funk/fundaemon_client.pm), but i have the same
> problem as before :(
> 
> Simon Funke
> 

You're still not creating the object correctly:

  my $client = IO::Socket::UNIX->new (

  #NOT my $client = new IO::Socket::UNIX (

and the argument is PeerAddr, not Peer

As for the error about global symbol...you need to get in the habit of
using my and our to scope your variables in perl.  If you haven't
already, read perldoc perlintro.  Also take a look at perldoc
perlboot, etc., on object-oriented perl.  Also read the docs for
IO::Socket, and ake sure you're reading the documentation for
IO::Socket, not Socket, or the built-in functions.  They're all very
different things.

HTH, --jay

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl Socket Client for C++ Server

2005-04-07 Thread news-funsi
Hi Jay,

thanks for the answer. 

> Firt things first.  Why did you comment out use strict?  That's never
> a good sign.  also, loading both IO::Socket::Unix and Socket probably
> isn't the best idea.  the main problem here, though would seem to be
> mixing your syntax.  You're calling the object-oriented IO::Socket
> interface, but you're using it like you would the builtin functions. 
> You're also using incorect argument names.  
Your right. It was a dirty hack, and because it did not work with
IO::Socket::Unix, i tried the Socket library.

i'm playing with your version
(http://www.honktown.de/funk/fundaemon_client.pm), but i have the same
problem as before :(

Simon Funke


-- 
Sparen beginnt mit GMX DSL: http://www.gmx.net/de/go/dsl

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl Socket Client for C++ Server

2005-04-06 Thread Jay Savage
On Apr 6, 2005 1:41 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> thanks zentara for the answer, but unfortunately this does not work.
> 
> I've uploaded the the C++ server/client and the testclient for perl.
> 
> after unpacking and compiling the fundaemon, the server executable is
> src/fundaemon, which will create a file called /tmp/fundaemon_socket and
> listens for clients.
> the c++ testclient is called "testclient", and has a small menu to control
> the server.
> 
> C++ Server and Client
> www.honktown.de/funk/fundaemon.tar.bz2
> 
> Perl Client:
> http://www.honktown.de/funk/fundaemon_client.pm
> 
> greetings,
> 
> Simon Funke
> 

#!/usr/bin/perl

use IO::Socket;
#use strict;
use Socket;

#use strict;
my $client;

onLoad();
onUnLoad();

sub onLoad {
 $client = new IO::Socket::UNIX (
Type => SOCK_STREAM,
Peer => "/tmp/fundaemon_socket",
Timeout => 5,
)
or die $@;
sleep(1);
 print $client sprintf("%u%d", 0,2);
sleep(1);
 print $client sprintf("%u%d", 0,2);
sleep(1);
 print $client sprintf("%c", 0);
sleep(1);
 print $client sprintf("%d\n", 05);

#socket($socket, PF_UNIX, SOCK_STREAM, 0);
#$client = sockaddr_un('/tmp/fundaemon_socket');
#connect($socket, $client);

sleep (5);
#print $socket '02fewfewfewfewggg';
#print $socket sprintf( "%d%d", 0, 2);

#sleep 10;

}


sub onUnLoad {
  my ($self)[EMAIL PROTECTED];
  close ($client);
}



Simon,

Firt things first.  Why did you comment out use strict?  That's never
a good sign.  also, loading both IO::Socket::Unix and Socket probably
isn't the best idea.  the main problem here, though would seem to be
mixing your syntax.  You're calling the object-oriented IO::Socket
interface, but you're using it like you would the builtin functions. 
You're also using incorect argument names.  Take another look at the
docs for IO::Socket.  To get you started, though, see if this doesn't
work better for you:

#!/usr/bin/perl

use IO::Socket;
use strict;
use warnings;

my $client = IO::Socket::UNIX->new (
Type => SOCK_STREAM,
PeerAddr => "/tmp/fundaemon_socket",
Timeout => 5,
)
or die $@;
sleep(1);
 print $client sprintf("%u%d", 0,2);
# better yet, make sure that buffering is handled correctly:
$client->send($msg) ;

HTH,

--jay

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl Socket Client for C++ Server

2005-04-06 Thread news-funsi
thanks zentara for the answer, but unfortunately this does not work.

I've uploaded the the C++ server/client and the testclient for perl.

after unpacking and compiling the fundaemon, the server executable is
src/fundaemon, which will create a file called /tmp/fundaemon_socket and
listens for clients. 
the c++ testclient is called "testclient", and has a small menu to control
the server.

C++ Server and Client
www.honktown.de/funk/fundaemon.tar.bz2


Perl Client:
http://www.honktown.de/funk/fundaemon_client.pm

greetings,

Simon Funke

-- 
Handyrechnung zu hoch? Tipp: SMS und MMS mit GMX
Seien Sie so frei: Alle Infos unter http://www.gmx.net/de/go/freesms

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Perl Socket Client for C++ Server

2005-04-05 Thread news-funsi
Hi there,

i have written a socket c++ server, which listens for clients and
understands   some commands. 
here the structs of the server commands:


enum command { SET_PRIO, CLEAR, SEND_STRING, SET_CURSOR, SHOW_CURSOR };

struct string_packet_t
{
  char str[DATA_LENGTH];
};

struct int_packet_t
{
  int data;
};

 
struct cmd_packet_t
{
  command type; 
  union
  {
int_packet_t int_pkg;
string_packet_t str_pkg;
  };
};

a c++ client would now send following command over the socket to the the
server:

  cmd_packet_t command;
  command.type=SEND_STRING;
  strcpy(command.str_pkg.str, "Hello World");
  write(fd, &command, sizeof(command);

with c/c++ all is working fine. 

The problem is the perl client. after setting up the socket i tried:

print SOCKET sprintf(%u%d, 0, 2)
# 0 For the first command == SET_PRIO, 2 for the argument
but the server receives no useable data.
("12848" for the command value, instead of 0 and
 "1" for the integer argument)

any idea?

thank,

Simon Funke

-- 
Sparen beginnt mit GMX DSL: http://www.gmx.net/de/go/dsl

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]