473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Read from perl socket

2
Hi,

How do I read data from perl socket.
I tried these three methods in bold but nothing worked.

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use IO::Socket;
  3. use HTTP::Request::Common;
  4. use LWP::UserAgent;
  5. use LWP::Simple;
  6.  
  7. my $host = shift || ‘mysite.com';
  8. my $port = shift || 80;
  9. my $sock = new IO::Socket::INET(
  10.                   PeerAddr => $host,
  11.                   PeerPort => $port,
  12.                   Proto    => 'tcp');
  13. $sock or die "no socket :$!";
  14. # send message to server
  15.  
  16. my $ua = LWP::UserAgent->new;
  17. $ua->request(POST 'http://mysite.com/check.cgi', ["value1" => "xyz","passwd" => "value2", "abc" => "existing"]);
  18.  
  19. my $query = $ua->request(POST 'http://mysite.com/check.cgi', ["value1" => "xyz","passwd" => "value2", "abc" => "existing"]);
  20. print $sock $query;
  21.  
  22. while (<$sock>) {
  23. print;
  24. }
  25.  
  26.  
  27. My $buffer;
  28. recv ($sock, $buffer);
  29. my $result = recv ($sock, $buffer);
  30. print $result;
  31.  
  32.  
  33. my $data;
  34. $sock->read($data,1024) until $sock->atmark;
  35. my $result = $sock->read($data,1024) until $sock->atmark;
  36. print $result;
  37.  
Thanks in advance.
Sep 28 '07 #1
0 2554

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Wayne Folta | last post by:
I've been a long-time Perl programmer, though I've not used a boatload of packages nor much of the tacky OO. A couple of years ago, I decided to look into Python and Ruby. Python looked OK, but...
0
by: GMane Python | last post by:
Hello Everyone. Whil e reading the Python Cookbook as a means of learning Python, I came across the script by Nicola Larosa. Not knowing anything about PERL, I was wondering if there were a...
1
by: Patrick LeBoutillier | last post by:
Hi all, I'm trying to perform read and write I/O on a socket file descriptor received for another process via a Unix Domain Socket. In trying to understand all this I came up with a small test...
3
by: Jason Miles | last post by:
Hi, I wrote this little script to check to see if our Lotus Notes servers are running, and from the command line it works fine if I type perl notescheck.pl When I invoke the script from a web...
0
by: JL | last post by:
Platform: Linux Red Hat RHEL 3 (and red hat 9) Installed MySQL from source. As a matter of fact, installed all LAMPS from source, and the mysql socket file was arranged in a place other than...
2
by: facade21 | last post by:
i am trying to convert a code of php to perl in php we use $_cookie to retrieve cookie value i have to do the same in perl i have got the cookie some how , but i dont know how to...
0
by: muraley | last post by:
Hi, This client-server script does bi-directional communication. Setup i used: The server script on windows 2003 server and the client on a linux machine. Since i faced issues in getting the...
8
by: perln00b | last post by:
I cant find mistake in following code: #!/usr/bin/perl use Socket; $host=<STDIN>; chomp($host); $port=<STDIN>;
6
darksteel21
by: darksteel21 | last post by:
Hi to all, I am currently developing an application in perl that is capable of connecting to a server and sends information.. the server has a deamon that listens to the socket connections. It...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.