473,659 Members | 2,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

31 New Member
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
  3.  
  4. use strict;
  5. use Socket;
  6. use HTTP::Response;
  7. use LWP::UserAgent;
  8. use LWP::Simple;
  9. use LWP 5.64;
  10.  
  11. # use port 6555 as default
  12. my $port = shift || 6555;
  13. my $proto = getprotobyname('tcp');
  14.  
  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: $!";
  18.  
  19. # grab a port on this machine
  20. my $paddr = sockaddr_in($port, INADDR_ANY);
  21.  
  22. # bind to a port, then listen
  23. bind(SERVER, $paddr) or die "bind: $!";
  24. listen(SERVER, SOMAXCONN) or die "listen: $!";
  25.  
  26. print "SERVER started on port $port\n";
  27.  
  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);
  35.  
  36.     my $pid = fork();
  37.     if ($pid == 0) {
  38.         &connection;
  39.     }
  40.     close SERVER or die "close: $!";
  41. }
  42.  
  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. }
  50.  

Thanks in advance
Vasudha
May 4 '07 #1
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
May 4 '07 #2
vasu1308
31 New Member
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
May 4 '07 #3

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

Similar topics

0
1669
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...
8
21906
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...
12
7169
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
0
1380
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...
0
18451
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...
2
10780
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. ...
0
2623
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:
2
5174
by: semedao | last post by:
Hi , someone know the reason and how to handle it? thanks
1
4449
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:
0
8851
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, 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...
0
8747
jinu1996
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...
0
8627
tracyyun
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...
0
7356
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, 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...
1
6179
isladogs
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...
0
5649
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();...
0
4175
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...
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
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...

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.