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 8387399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:11:59+00:00 2026-06-09T18:11:59+00:00

I’m trying to make a simple listener on port 8195. When I try the

  • 0

I’m trying to make a simple listener on port 8195. When I try the following code block in PHP CLI conditions, it only shows ‘Test’ once, then hangs. If I delete the file ‘votifier.run’, the file designed to be the on/off switch, it still continues to hang. It never shows ‘Client connected’.

Furthermore, if I try to connect to the host via Telnet on port 8195 while the script is running, I simply get a connection failed message. It’s like it’s looking for one connection and just not giving up.

// Set the IP and port to listen to
$address = 'localhost';
$port = 8195;

// Create a TCP Stream socket
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
// Bind the socket to an address/port
socket_bind($sock, $address, $port);
// Start listening for connections
socket_listen($sock);

// Loop continuously
while ( file_exists('votifier.run') ) {
    echo 'Test';
    $client = socket_accept($sock);
    if( $client ) {
            echo 'Client connected';
            // Don't hang on slow connections
            socket_set_timeout($client, 5);

            // Send them our version
            socket_write("VOTIFIER MCWEBLINK\n");

            // Read the 256 byte block
            $block = socket_read($client, 256);
            ...

The answer:
socket_accept() will usually hang until a connection is made. If a connection attempt was made, the script would continue, but because the socket was being created on localhost, it would only accept connections to it from localhost.

The fix is to use your external IP rather than ‘localhost’ or ‘127.0.0.1’. Then you can Telnet to it.

  • 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-09T18:12:01+00:00Added an answer on June 9, 2026 at 6:12 pm

    I’m just guessing here, but could it be that the address you are trying to bind to should not be a hostname?

    If the socket is of the AF_INET family, the address is an IP in dotted-quad notation (e.g. 127.0.0.1).

    EDIT

    Ok, I’ve taken your script and tried to reproduce your error but couldn’t. There are a couple of flaws in it but none that would cause a telnet client’s connection attempt to fail.

    Since none of the aforementioned applies, let’s go thru the checklist one by one:

    • sockets module loaded/compiled
    • localhost does resolve to 127.0.0.1
    • the port isn’t taken by any other application running
    • there’s no rule of any sort of firewall that would prevent communication between the telnet client and your server
    • the machine which you connect from is allowed to connect to the server host (try the same host if it isn’t)
    • the file that’s being checked in the while-loop does exist
    • you are sure that there isn’t another fatal error within your script that would prevent the snippet you posted from running

    These are all the possible error sources I can think of, atm. Try fixing up the minor flaws first, then go thru the checklist.

    if( $client ) {
        echo 'Client connected';
        // Don't hang on slow connections
        socket_set_option(
            $client,
            SOL_SOCKET,
            SO_RCVTIMEO | SO_SNDTIMEO,
            array('sec' => 5, 'usec' => 0)
        );
    
        // Send them our version
        socket_write($client, "VOTIFIER MCWEBLINK\n");
                     ^^^^^^^
    
        // Read the 256 byte block
        $block = socket_read($client, 256);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to create an if statement in PHP that prevents a single post
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.