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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:14:56+00:00 2026-06-11T10:14:56+00:00

to begin with the fputs works for sending chat from the PHP site to

  • 0

to begin with the fputs works for sending chat from the PHP site to this gaming server. But when I use fgets to get all the chatlogs from the server it doesnt return it, bascially for example when I write something in the textfield and send it using the button in the following code, it sends message to the server, I want it to return that value back from the server, or get all the chatlogs from the server and put it into the client which is a php website, here is the code:

 <?php

 $host="192.168.0.6";
 $port = 7777;
 // open a client connection
 $fp = fsockopen ($host, $port, $errno, $timeout);
 if (!$fp){
 $result = "Error: could not open socket connection";
 }
 else
 {

  echo '<center><form action="tcpclient.php "method="POST" /></center>';
  echo '<center>'."Nickname: ".'<input type="text" name="nick" size="31" /></center>';
  echo '<center>'." Text: ".'<input type="text" name="chat" size="150" /> <input type="submit" name="send" value="Send"  /></center>';

  if (isSet($_POST['send'])) $formvalue =$_POST['chat'];
  //$name = $_POST['nick'];
  //if (isSet($_POST['send'])) $formvalue + $_POST['chat']; 
  fputs ($fp, $formvalue);

  }
  $result = fgets ($fp, 7777);
  echo $result;

  ?>
  • 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-11T10:14:57+00:00Added an answer on June 11, 2026 at 10:14 am

    fgets() only reads one line (terminated by "\n") and will block until "\n" is received or the connection is closed. Make sure one of these things happens. (Use telnet or nc programs)

    Oh and I’m not sure, but it might be expecting "\r\n" on Windows, and won’t react to "\n" alone. Don’t take my word on it though.

    If there is no newline, use fread and a combination of stream_select and stream_set_blocking (refer to the manual).

    If it’s anything even more complex, you might want to switch to socket_* functions. Note that sockets and streams don’t mix.


    Sorry, I’m too lazy for an example. You can look here for a general example of stream_select in action (disclaimer: the code is ugly, I know.)

    Basically, you’d stream_set_blocking to 0 and loop with stream_select and fread until you’ve read everything (if you can detect that) or hit a timeout. It’s hard to suggest anything not knowing the protocol.

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

Sidebar

Related Questions

I'm just begin upgrade my asp.net site from Webform to MVC 2. So far
To begin with, I would normally opt to use a pre-compiled binary of PHP,
To begin with, this question is not a dup of this one , but
To begin i read all resources from xml in my MergedDictionaries and now I
To begin with, I LOVE LINQ TO SQL. It's so much easier to use
Cloud server begin generate big disk read/write operation. I want find some script who
To begin with, I know very little about DTSX files and SSIS, but my
I begin to use git for software development. I have a project on github.
To begin, I'm working entirely in PHP using the Yii framework, although Yii ultimately
To begin with, this is the first Android app I'm writing, and I have

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.