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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:43:12+00:00 2026-05-20T23:43:12+00:00

So, i have mIRC making a listen (bear with me on this one) on

  • 0

So, i have mIRC making a listen (bear with me on this one) on port 1235 and i tried to make a php script to connect to such port on my localhost server.

My localhost is a clean Apache+PHP with mIRC being run on another computer (inside lan).

The script works half-right as:
1) it connects to the 1235 port
2) it sends the $i
2.1) but on the other side no msg is recieved (aka I get a sock read event but no text pops up)
3) it reads all the incoming messages correclty
4) it closes when ‘end’ is the message
drumroll
5) it only works IF the while function isn’t present.
5.1) aka Inifi-loading. it only shows echo when socket is closed via ‘end’

here is the code, which is a simple example i found on php.net, thanks in advance 🙂

    <?php
//The Client
error_reporting(E_ALL);

$address = "192.168.1.101";
$port = 1235;

/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
    echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
    echo "socket successfully created.\n";
}

echo "Attempting to connect to '$address' on port '$port'...";
$result = socket_connect($socket, $address, $port);
if ($result === false) {
    echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
    echo "successfully connected to $address.\n<br>";
}
$allow = true;
$i = 0;
while ($allow == true)
{
    $i++;
    echo "Sending $i to server.\n<br>";
    socket_write($socket, $i, strlen($i));

    $input = socket_read($socket, 2048);
    if ($input == 'end') {
        $allow = false; 
    }
    echo "Response from server is: $input\n";
    sleep(5);
}

echo "Closing socket...";
socket_close($socket);
?>

this is what i get in browser, after saying ‘end’

socket successfully created.
Attempting to connect to
‘192.168.1.101’ on port
‘1235’…successfully connected to
192.168.1.101. Sending 1 to server. Response from server is: ok
Response from server is: end

this is in mIRC:

test: 89.152.172.21 is in!
read
close
Blockquote

if i had left it working for an hour, multiply “read” for 60 and “sending N+1 to server”
but this only shows up AFTER sock close (or by stoping the while)

  • 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-20T23:43:13+00:00Added an answer on May 20, 2026 at 11:43 pm

    You have “plain” socket_write() and socket_read() calls. Unfortunately socket functions are unreliable by design (that’s behavior inherited from BSD sockets). You can’t just call socket_write() and expect it to actually write bytes (as odd as it sounds…)

    PHP manual quote:

    socket_write() does not necessarily write all bytes from the given buffer. It’s valid that, depending on the network buffers etc., only a certain amount of data, even one byte, is written though your buffer is greater. You have to watch out so you don’t unintentionally forget to transmit the rest of your data.

    You have to check how many bytes have been written and keep retrying until all you wanted has been sent.

    The same goes for reading. Read call can read as much as you requested or less and you’re expected to retry the call.

    Make sure to set sockets to blocking and then call read/write in a loop, or use (equally awful) select() call to find which sockets may have some data or may have finished sending.


    If you want API that’s not such PITA, then use streams instead, which have reliable reads/writes.

    If you don’t necessarily need PHP, then have a look at Node JS, which is specially designed server/environment for programs with long-lived network connections.

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

Sidebar

Related Questions

Have you tried to use SharePoint with version control such as Perforce (or Subversion),
Have a look at this url: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jquery_ui_methods#column_chooser I have got the Column Chooser dialog
have Googled the cr*p out of this one so apologies if the answer is
Have any one tried to activate fancybox thumbnail gallery using a button or an
Have you managed to get Aptana Studio debugging to work? I tried following this,
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
Have someone tried out DeCAL in Delphi 2009? I'm thinking about upgrading from 2007,
Have you ever tried learning a language while on a project? I have, and
Have converted devise new session from erb to Haml but doens't work, this is
have anyone can tell me what syntax error on this actionscript (actionscript3.0)? var rotY:

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.