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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:03:05+00:00 2026-05-21T10:03:05+00:00

I have the following code: http://pastebin.com/U9qYSmET When I try to telnet into my server

  • 0

I have the following code: http://pastebin.com/U9qYSmET

When I try to telnet into my server and port with

telnet localhost 6667

I get the following error:

PHP Warning: socket_read(): unable to read from socket [107]: Transport endpoint is not connected in /var/www/php-irc/proxy.php on line 91

Anyone have any ideas why I’m getting this error?

Code:

<?php 

if(!defined('SOCKET_ADDRESS')) {
    define('SOCKET_ADDRESS', '127.0.0.1');
}

if(!defined('SOCKET_PORT')) {
    define('SOCKET_PORT', '6667');
}

if(!defined('MAX_CLIENTS')) {
    define('MAX_CLIENTS', '10');
}
set_time_limit(0);

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($socket, SOCKET_ADDRESS, SOCKET_PORT) or die('Could not bind to address ' . SOCKET_ADDRESS . ' on port ' . SOCKET_PORT . "!\n");
socket_listen($socket, MAX_CLIENTS) or die ("Could not setup socket listener!\n");

// setup read socket array
$read = array();

// client array w/ default initial socket
$clients = array('0' => array('socket' => $socket));

// force debug at first run..
$debug = true;
$time = time();
printf('Time: %d%s', $time, "\n");
while(true) {

    if(time() - $time >= 10) {
        $time = time();
        printf('Time: %d%s', $time, "\n");
        $debug = true;
    }
    if($debug === true) {
        printf('Debug: %s%s', $debug, "\n");
    }
    // $read[0] = $socket;
    if($debug) {
        var_dump($read);
    }

    // Handle clients
    for($i = 0; $i < count($clients); $i++) {
        if(isset($clients[$i]['socket'])) {
            if($debug === true) {
                printf('Setting socket %d to client %d%s', $i, $i, "\n");
            }
            $read[$i] = $clients[$i]['socket'];
        }
    }
    if($debug) {
        var_dump($read);
    }
    // Any changed sockets?
    // $write and $except are only placeholders
    $changed_sockets = socket_select($read, $write = NULL, $except = NULL, 0);
    if($debug === true){
        printf('Changed sockets: %d%s', $changed_sockets, "\n");
    }
    // Handle new connections
    if(in_array($socket, $read)) {
        for($i = 0; $i < MAX_CLIENTS; $i++) {
            if(!isset($clients[$i])) {
                $clients[$i]['socket'] = socket_accept($socket);
                socket_getpeername($clients[$i]['socket'],$ip);
                $clients[$i]['ip'] = $ip;
                printf('Accepting connection into client %d from %s%s', $i, $ip, "\n");
                break;
            }
            // } elseif($i == MAX_CLIENTS - 1) {
                // echo 'Too many clients connected!', "\n";
            // }
            if($changed_sockets < 1) {
                continue;                
            }
        }
    }
    if($debug) {
        var_dump($clients);
    }

    for($i = 0; $i < count($clients); $i++) {
        $client = $clients[$i];
        // Has our client socket seen any changes?
        if(in_array($client['socket'], $read)) {
            printf('Client %d has changed! Reading...%s', $i, "\n");
            $data = socket_read($client['socket'], 1024);
            if($data === false) {
                $error = socket_strerror(socket_last_error());
                printf('An error occured...%s%s', $error, "\n");

            }
            printf("Read raw data %s from client %i%s", $data, $i, "\n");
            if($data === null) {
                // disconnected
                unset($clients[$i]);
            }

            $data = trim($data);
            if($data == 'exit') {
                printf('Received exit command from client%s', "\n");
                socket_close($clients[$i]['socket']);
            } elseif($data) {
                // Strip whitespace
                printf('Received data: %s from client %d%s', $data, $i, "\n");
                $output = sprintf('%s%s%s', $data, "\n", chr(0));
                socket_write($client['socket'], $output);
            }
        }
    }

    // reset debug
    $debug = false;
}

socket_close($socket);
  • 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-21T10:03:06+00:00Added an answer on May 21, 2026 at 10:03 am

    The problem was it was trying to read from $clients[0]. Which isn’t a valid client to be reading from. I simply changed the last two for loops to start $i at 1.

    So far in my testing, this doesn’t seem to be having any adverse affects. The error is gone, and I all of the client instances appear to be working fine.

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

Sidebar

Related Questions

I have the following code: http://www.nomorepasting.com/getpaste.php?pasteid=22615 Which is called by the javascript mentioned in
I have to following code: http://www.nomorepasting.com/getpaste.php?pasteid=22987 If PHPSESSID is not already in the table
i have the following string: http://pastebin.com/d29ae565b i need to separate each value and put
I have the following code: $.get('http://www.example.org', {a:1,b:2,c:3}, function(xml) {}, 'xml'); Is there a way
I have the following code: $string = '[url]http://google.com[/url]'; $bbreplace = array ('/\[url\](.+?)\[\/url\]/'); $bbreplacements =
I have the following code in PHP $ch = curl_init(http://blog.com); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch,
I have the following code on(press){ gotoAndPlay(193); } on(release) { getURL(http://www.sumangalijewellers.com); } when I
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
Possible Duplicate: splitting a string i have a string which looks like this: http://pastebin.com/m5508ff19
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public

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.