|
|
john_pataki@xxxxxxxxx wrote:
> Intro...
>
> I am writing sort of a bridge out of an API for our software - I
> managed to get some help on the JAVA side (our API is JAVA) to put
> together a small app
> that will listen to and send messages through a socket. So
> far it works
> great - I wrote a little test app in Tk to emulate sending
> and receiving
> messages betweeen the app - I am realizing how nice it is to work with
> sockets - I love 'em! The are fast!!! - they don't get stuck
> or seem to
> lock up the machine like reading and writing to files - they
> work across the
> network - they are non-platform specific.
>
> Here is my code so far - this works - questions follow the code ...
>
> ----------------------begin test_socket_client.pl
> -----------------------
>
> $sock = IO::Socket::INET-> new(PeerAddr => "$host:$port");
> die "Cannot connect" unless defined $sock;
>
> $sel = IO::Select-> new;
> $sel-> add($sock);
>
> &build_gui; # I left out this routine - not relavent here
You should call subroutines without '&', unless you know what it does.
>
> $mw-> repeat(50 => \&read_sock);
>
> sub write_sock {
>
> $text->insert('end',"Client: @_\n");
> syswrite $sock, "@_\n";
>
> } # end sub
>
> sub read_sock {
>
> my $line;
> my $buf;
>
> my(@ready) = $sel-> can_read(0);
> return if $#ready == -1;
> my $hand = $ready[0];
>
> sysread $hand, $buf, 80;
> $line .= $buf;
> $text->insert('end',"Server: $line\n");
>
> } # end sub
>
>
> ---------------------- end test_socket_client.pl
> -----------------------
>
> Questions:
>
>
> Since I am on Win32 and fileevent does not work reliably I
> must use the
> repeat every 50 milliseconds approach from Tk ...
>
> As I test this I can see that if the code on the other spits
> out a ton of
> data - it all ends up in my text widget - with the newlines
> in the correct
> place. But I am not sure if it is getting written line by line - or in
> chunks of arbitray size of what is was able to read in that
> burst it read
> ... or in chunks of exactly 80 characters?
>
> Also - how can tell when the data stream is over for the
> current message?
> Is there a built in EOF-like check I can make?
>
> What I really want is to check the socket for a message -
> then - be able to
> read until the message is over - but to know when the message
> is really over
> and not just delayed due to network traffic of if the sending
> application is slow or something. And .. If it reads X characters on
> this
> call .. and then
> it ends because at that moment there is nothing there - how
> will I know it
> is really over .. and another call 50 milliseconds later is
> supposed to be a
> continuation or is it really a new message all together sent
> not by request
> by me - but because the other end initiated it?
>
> So - are there already known standards for indicating begin
> this message,
> end message here --- or I am going to send you a message and it is X
> characters or lines long?
>
> Before I sit down and create my own set of standards for this - it
> would be nice to know if one already exists or if it is even built in.
There are no real standards for this. If you are incontrol of the
protocol then you get to say how to identify the start and end of a
'message' in what is essentially a byte stream. A common technique used
in text based protocols (SMTP, POP3 ...) is to indicate the end of a
multi-line block of data by sending a line containing just '.'. Take a
look at Net::Cmd which implements this and is a base class for other
text protocols under Net. If you can't use it, it may give you some
clues.
>
> Also -
>
> 1) a standard for sending a call to a function on the other end
> 2) a standard for handling the format for output from the function
> 3) a standard for handling error messages from the function
> just called - is
> there some parallel handle to check for errors? Like STDERR?
There are plenty of standards for this, e.g. CORBA. If you want
something simpler, take a look at SOAP. It comes as standard with
Activestate Perl (it is used by ppm), and should be supported in Java.
>
> One thought I had was to open socket just for handling the
> function call
> messages & limits & arguments, one socket for data chunks
> (multi-line) to go back and forth and another for error messages -
> but this
> seems like a waste
> of resources - standard seems like a better approach.
HTH
--
Brian Raven
-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely
for the intended addressee(s). Unauthorised reproduction, disclosure,
modification, and/or distribution of this email may be unlawful. If you
have received this email in error, please notify the sender immediately
and delete it from your system. The views expressed in this message
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary
companies.
-----------------------------------------------------------------------
_______________________________________________
ActivePerl mailing list
ActivePerl@xxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
|
|