Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9019895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:52:52+00:00 2026-06-16T04:52:52+00:00

I have the following subroutine: use Socket … sub proxy_connect { my $iaddr =

  • 0

I have the following subroutine:

use Socket
...
sub proxy_connect {
   my $iaddr = Socket::inet_aton($proxy);
   my $paddr = Socket::sockaddr_in(81, $iaddr);
   my $proto = getprotobyname('tcp');
   my $fh    = new FileHandle;

   socket($fh, PF_INET, SOCK_STREAM, $proto) or return;


   connect($fh, $paddr) or return;
   $fh->autoflush(1);
   # return a pointer to file handle
   return \$fh;
}
my $mysock = proxy_connect();

The Python approach is totally different, and instead of returning a File object I return a socket, but I am not sure the functionality is exactly the same:

  import socket
  ...
  def proxy_connect():
     """
     Connect to the proxy and return a filehandle for it.
     """
     proxy = "proxy.mydomain.com"
     address = socket.gethostbyname(proxy)
     con = socket.socket(
     socket.AF_INET, socket.SOCK_STREAM)
     con.connect((address, 81))
     return con

Am I on the right path to translating this tunnel-ssh-over-http?
Note, I am quite novice in Perl, and this just done as an exercise to learn some more stuff about Perl and sockets (in Python).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:52:53+00:00Added an answer on June 16, 2026 at 4:52 am

    Yes, you can do a straight forward conversion. select() will behave the same in Python, allowing you to test for data-ready-to-read on the sockets. In Perl, they are using vec() but in Python you test whether your socket is in the return value of select(). In Perl where they sysread/syswrite you would instead use socket.recv() socket.send()

    The do_copy routine is almost a straight translation, except that socket.send() doesn’t take an offset/len, so you will need to slice the buffer yourself if socket.send() doesn’t indicate the entire buffer was sent.

    The SELECT loop will work the same way as in the perl code. You’ll pass in the sockets you want to test for readability, and do something like:

    readable, writeable, exceptional = 
          select.select([socket1, socket2], 
                        None, [socket1, socket2])
    if socket1 in readable:
       do_copy(socket1, socket2)
    if socket2 in readable:
       do_copy(socket2, socket1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following subroutine: Private Sub MySub(ByVal sender As System.Object, ByVal e As
Here is what I have as VBScript Subroutine: sub buildChildAdminStringHierarchical(byval pAdminID, byref adminString) set
I have the following FORTRAN SUBROUTINE SETPATHS(INPUT) !DEC$ ATTRIBUTES DLLEXPORT::SetPaths CHARACTER*20 INPUT CHARACTER*20 DIRECTORY
I have the following FORTRAN: SUBROUTINE MYSUB(MYPARAM) !DEC$ ATTRIBUTES DLLEXPORT::SetPaths CHARACTER*50 MYPARAM WRITE(6, *)
I have encountered a difficulty in understanding the subroutine syntax. using the following code:
I have a module with the following subroutines: package module; sub new { my
I have the following program module test contains subroutine foo() integer, allocatable :: a(:)
Consider following simple example: #!perl -w use strict; sub max { my ($a, $b)
I have the following subroutine OutputingReorderedVectors, which aims to output vectors following some pre-specified
Suppose we have a subroutine returning a reference sub aspirin { my @items =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.