473,372 Members | 847 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,372 software developers and data experts.

Error occured "accept() on closed socket SERVER at proxy.pl line"

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.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. # server1.pl - a simple server
  4. use strict;
  5. use Socket;
  6. use HTTP::Response;
  7. use LWP::UserAgent;
  8. use LWP::Simple;
  9. use LWP 5.64;
  11. # use port 6555 as default
  12. my $port = shift || 6555;
  13. my $proto = getprotobyname('tcp');
  15. # create a socket, make it reusable
  16. socket(SERVER, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
  17. setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) or die "setsock: $!";
  19. # grab a port on this machine
  20. my $paddr = sockaddr_in($port, INADDR_ANY);
  22. # bind to a port, then listen
  23. bind(SERVER, $paddr) or die "bind: $!";
  24. listen(SERVER, SOMAXCONN) or die "listen: $!";
  26. print "SERVER started on port $port\n";
  28. my $client_addr;
  29. while (1) {
  30.     # find out who connected
  31.     $client_addr = accept(CLIENT,SERVER);
  32.     my ($client_port, $client_ip) = sockaddr_in($client_addr);
  33.     my $client_ipnum = inet_ntoa($client_ip);
  34.     my $client_host = gethostbyaddr($client_ip, AF_INET);
  36.     my $pid = fork();
  37.     if ($pid == 0) {
  38.         &connection;
  39.     }
  40.     close SERVER or die "close: $!";
  41. }
  43. sub connection() {
  44.     my $url = 'http://www.cs.memphis.edu/';
  45.     my $browser = LWP::UserAgent->new;
  46.     my $response = $browser->get( $url );
  47.     my $result= $response->content;
  48.     print CLIENT $result;
  49. }

Thanks in advance
May 4 '07 #1
2 2427
1,089 Expert 1GB
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
May 4 '07 #2
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.

May 4 '07 #3

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...
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...
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...
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...
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...
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...
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...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.