Hi all
I am working on a socket program in Perl. Main goal is to develop a proxy server. Here is the code attached. An error is encountered. Anyone Please help me out. -
#!/usr/bin/perl -w
-
# server1.pl - a simple server
-
-
use strict;
-
use Socket;
-
use HTTP::Response;
-
use LWP::UserAgent;
-
use LWP::Simple;
-
use LWP 5.64;
-
-
# use port 6555 as default
-
my $port = shift || 6555;
-
my $proto = getprotobyname('tcp');
-
-
# create a socket, make it reusable
-
socket(SERVER, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
-
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) or die "setsock: $!";
-
-
# grab a port on this machine
-
my $paddr = sockaddr_in($port, INADDR_ANY);
-
-
# bind to a port, then listen
-
bind(SERVER, $paddr) or die "bind: $!";
-
listen(SERVER, SOMAXCONN) or die "listen: $!";
-
-
print "SERVER started on port $port\n";
-
-
my $client_addr;
-
while (1) {
-
# find out who connected
-
$client_addr = accept(CLIENT,SERVER);
-
my ($client_port, $client_ip) = sockaddr_in($client_addr);
-
my $client_ipnum = inet_ntoa($client_ip);
-
my $client_host = gethostbyaddr($client_ip, AF_INET);
-
-
my $pid = fork();
-
if ($pid == 0) {
-
&connection;
-
}
-
close SERVER or die "close: $!";
-
}
-
-
sub connection() {
-
my $url = 'http://www.cs.memphis.edu/';
-
my $browser = LWP::UserAgent->new;
-
my $response = $browser->get( $url );
-
my $result= $response->content;
-
print CLIENT $result;
-
}
-
Thanks in advance
Vasudha
2 2440 miller 1,089
Recognized Expert Top Contributor
Hi Vasu,
When debugging code and an error occurs, It is often helpful to actually share what the error is. Also, please start including your code within CODE tags. I've had to fix this in your posts multiple times now.
- Miller
Hi Miller,
Sorry about that. The following are the errors encountered....
accept() on closed socket SERVER at proxyn.pl line 31.
Use of uninitialized value in subroutine entry at /usr/lib/perl5/5.8.0/i386-linux-thread-multi/Socket.pm line 370.
Bad arg length for Socket::unpack_ sockaddr_in, length is 0, should be 16 at /usr/lib/perl5/5.8.0/i386-linux-thread-multi/Socket.pm line 370.
Thanks
Vasu
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jwalton |
last post by:
I have a new Web Service (written in C#) that is giving me major problems.
The Consumer application is written in VB.NET. When executed totally on
localhost it works 100%. When standalone Web Service is executed on
production server using Form-based ASP.NET test mode, it works 100%. When
Web Service is executed on production server with Consumer on localhost it
works 100%. However when Web Service and Consumer are both executed
totally on...
|
by: Grant Richard |
last post by:
Using the TcpListener and TcpClient I created a program that just sends and
receives a short string - over and over again. The program is fine until it
gets to around 1500 to 1800 messages. At that time, I get a SocketException
with the message "Only one usage of each socket address (protocol/network
address/port) is normally permitted". This happen if you use localhost or
between two distinct computers. And, for a period of time after the...
|
by: Yarco |
last post by:
when doing fork in a loop:
while(1) {
tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
if (tmp_sd == -1) {
perror("accept");
exit(0);
}
//check client ip
|
by: jack |
last post by:
I have written a fairly simple c# server that uses asynchronous
sockets. I have two different clients that connect and send/receive
info from the server. Both exihibit this behaviour where everything
will work fine for a long while, but eventually the OnDataReceived
callback method throws an exception on the EndReceive method, with
socket exception "An existing connection was forcibly closed by the
remote host". I am reasonably sure the...
|
by: BGS |
last post by:
I have a web site (www.on-the-matrix.com) that displays photos in a "slide
show" format on ASPX pages that run in an inline frame on an ASP page (or in
a separate pop-up window). The ASPX pages use a hidden form to transmit
information back to the server so it will know which is the next photo to
load. All of this works as intended in modern versions of Internet
Explorer, Netscape and Mozilla.
With Opera, however, users receive a...
| |
by: Rossco |
last post by:
I have a VB.NET serviced component (COM+), running on a lan, that
calls out to an external web service to place an order with a
supplier.
The problem machine is the middle tier (COM+) for our in house
applications, and also has a mail server to service a 100 stores
(don't ask me why, I don't like this either).
The call to the webservice works correctly on our test COM+ machine
but fails on the production machine with the above error. ...
|
by: lpinho |
last post by:
Hi There,
I've generated a C# file from a wsdl file using wsdl.exe utility.
Then I created a console application and made a call to the method
generated, first I got the error:
"The request failed with HTTP status 407: Proxy Access Denied."
Then I added a proxy validating and proxy credentials and got this:
|
by: semedao |
last post by:
Hi ,
someone know the reason and how to handle it?
thanks
|
by: Almund |
last post by:
Hi,
I'm trying to implement streaming over http and got stuck with a problem trying to send chunks of data using the .Net NetworkStream object.
All works fine as long as I send the entire data in one invocation to the NetworkStream, like:
_stream.Write(buffer, 0, buffer.Length)
But if i try:
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |