ramprasadgk has asked for the wisdom of the Perl Monks concerning the following question:
when I run the server program followed by client , java socket reads the input from perl socket but in perl I'm not able to receive data. can anyone suggest how to read from java socket in perl Hit me if I see to be less informative on this. thanking u in advancejava code:**SERVER** int port=5551; ServerSocket ss=new ServerSocket(port); // System.out.println("Waiting for lient"); Socket s=ss.accept(); // System.out.println("Waiting for clienttttt"); BufferedReader br=new BufferedReader(new InputStreamReade +r(s.getInputStream())); DataOutputStream pw = new DataOutputStream(s.getOutputStr +eam()); //PrintWriter pw=new PrintWriter(new OutputStreamWriter(s +.getOutputStream())) ; String str=br.readLine(); int n=Integer.parseInt(str); int i; long f=1; System.out.println("Number sent by client: " + n); for(i = 2; i <= n; i++) f = f * i; System.out.println("Number sent to client: " + f +n); pw.writeLong(f); perl code ***CLIENT**** use threads::shared; 2 use IO::Socket; 3 use IO::Select; #[/RP001] 4 use IO::Handle; 5 chomp(my $hostname = `hostname`); 6 7 my $dmx_sock = new IO::Socket::INET( 8 PeerAddr => $hostname, 9 PeerPort => 5551, 10 Proto => 'tcp', 11 ); 12 $dmx_sock or print "err"; 13 print $dmx_sock "2"; 14 sleep(5); 15 my $buf; 16 read($dmx_sock, $buf,1); 17 18 my ($tag,$code,$len) = unpack 'L', $buf; 19 print "\$tag = '$tag'\n"; 20 print "\$code = '$code'\n"; 21 print "\$len = '$len'\n"; 22 read($socket, $buf, $len); 23 print "\$buf = '$buf'"; 24 25 26 27 #$dmx_sock->close; 28 print "<<<$buf>>>>"; ~
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reading data from java socket
by zentara (Cardinal) on Sep 18, 2008 at 12:34 UTC | |
by Anonymous Monk on Sep 18, 2008 at 13:48 UTC |