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

  • SEARCH
  • Home
  • 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 7178503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:56:03+00:00 2026-05-28T16:56:03+00:00

I have a small web server script. If I set it to ‘localhost’ –

  • 0

I have a small web server script. If I set it to ‘localhost’ – then I can’t telnet to that port from outside. If I set it to the FQDN – then I can’t telnet like this: ‘telnet localhost 7777’. What is the proper way to name the host in this case?

$host = 'localhost';
$port = 7777;
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");

while(1)
{
    $spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
    $input = socket_read($spawn, 1024) or die("Could not read input\n");

    while(trim($input)!="")
    {
            $msg=$msg.$input;
            $input = socket_read($spawn, 1024) or die("Could not read input\n");
    }

    $webserver = new Server($msg);
    $output = $webserver->response();
    unset($msg);
    socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
    socket_close($spawn);

    }
  • 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-05-28T16:56:04+00:00Added an answer on May 28, 2026 at 4:56 pm

    Yes. You have two options. The easiest way is to bind the socket to 0.0.0.0, which will bind the socket to all the interfaces on the machine. (Make sure though, that you actually want all interfaces.)

    Otherwise, you can always create >1 socket, and bind them individually to the interfaces that make sense.

    You’re writing the whole webserver in PHP?

    Also, if PHP’s socket reading functions work like most operating systems, then your inner loop probably isn’t correct: while an HTTP request does end with a blank like, that doesn’t mean that the OS’s read function is going to segment data line by line.

    Edit: socket_read apparently will segment results by lines (this is unusual), but you need to specify it as the third parameter. According to the documentation, the default will not segment by line, but that this wasn’t always the case — i.e., the default changed. You should probably specify it to make sure your code doesn’t break when you upgrade. (And maybe upgrade, while you’re at it…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have small web app that generate PDF files as a report. I'm trying
I have a small console app containing a web server written in c#. When
I have written a small custom web server application in C running on Linux.
I have a small web.py Python application that I would like to serve under
I have a small script on artimap.com that I use to asychronously load images.
I currently have a small socket server that I'm trying to convert to a
I have a small web application with ASP.NET AJAX running well under the Cassini
We have developed a small web application for a client. We decided on the
I am a broke college student. I have built a small web app in
I'm making a small web application in Seaside. I have a login component, and

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.