• Home
  • Regtweaker
  • Subscribe to Posts
  • Subscribe to comments

PC solutions

Give you Professional Suggestions

  • Home
  • News
  • Registry
  • Script
  • System Utility
  • Virus
  • Windows
  • XML
Home Others Script PHP Socket Server Implementation

PHP Socket Server Implementation

Posted on Thursday, 27 May 2010
64 Comments
Share|

<?php
ob_implicit_flush();
set_time_limit(0);

$address = “192.40.7.93″;//Changed to your own address

$port = 10000;

if(($socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) == false)
 echo “error (socket_create):”.socket_strerror(socket_last_error()).”<br />”;
 
if(socket_bind($socket,$address,$port) == false)
 echo “Error (socket_bind):”.socket_strerror(socket_last_error()).”<br />”;
 
if(socket_listen($socket) == false)
 echo “Error (socket_listen):”.socket_strerror(socket_last_error()).”<br />”;
 
/*
After the socket socket has been created using socket_create() and bound to a name with socket_bind(),
it may be told to listen for incoming connections on socket.
*/

while(true){
 if(($msgSocket = socket_accept($socket)) == false){
  echo “Error (socket_accept):”.socket_strerror(socket_last_error()).”<br />”;
  break;
 }
 
 /*
 this function will accept incoming connections on that socket.
 Once a successful connection is made, a new socket resource is returned, which may be used for communication.
 If there are multiple connections queued on the socket, the first will be used.
 If there are no pending connections, socket_accept() will block until a connection becomes present.
 If socket has been made non-blocking using socket_set_blocking() or socket_set_nonblock(), FALSE will be returned. 
 */
 
 $msg = “Welcome!<br />”;
 //socket_write($msg,$msg,strlen($msg));
 $command = “”;
 
 while(true){
  if(($buf = socket_read($msgSocket,2048,PHP_BINARY_READ)) == false){
   echo “Error (socket_read):”.socket_strerror(socket_last_error()).”<br />”;
   break 2;
  }
  
  /*
  The function socket_read() reads from the socket resource socket created by the socket_create() or socket_accept() functions.
  The maximum number of bytes read is specified by the length parameter.
  Otherwise you can use \r, \n, or \0 to end reading (depending on the type parameter, see below).   
  */
  
  /*
  if(!$buf = trim($buf))
   continue; // ????
   
  if($buf == “quit”)
   break;
  
  if($buf == “shutdown”){
   socket_close($msgSocket);
   break 2;
  }
  
  $tallBack = “You say:$buf\n”;
  socket_write($msgSocket,$tallBack,strlen($tallBack));
  */
  
  if(ord($buf) != 13)
   $command .= $buf;
  else{
   $command1 = “You Say:$command\r\n”;
   socket_write($msgSocket,$command1,strlen($command1));
   echo “User typed:”.$command.”<br />”;
   $command = “”;
  }
 }
 socket_close($msgSocket);
}

socket_close($socket);
?>


Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl
Tagged with: PHP Server, PHP Socket, PHP Socket Server

64 Responses to “PHP Socket Server Implementation”

Trackbacks are disabled.

Cambria Heights NY garage door installation
simply orange coupon
Free Tarot Reading
barilla pasta coupon
cricut
nail forms
home article
best champagne
phone system Pawtucket MA
Cassey Laface
Eugenie
  • Cyber4Hacks.net says:
    2011-10-15 at 1:06 am

    Cyber4Hacks.net – Gaming, Hacking, Computing, Coding and more..

  • Matilde says:
    2011-09-2 at 4:09 am

    quality post…

    I have spent a bit of time going through your posts! http://cheap2012promdresses.spruz.com/pt/Prosperous-Page-Exhibits-Bulgari-125-Or-more-years/blog.htm,i had a good read….

  • Cander says:
    2011-08-18 at 4:43 am

    Great One…

    I must say, its worth it! My link, http://beatri.twoday.net/,thanks haha…

  • « Previous 1 2

    Leave a Reply:

    Click here to cancel reply.

    Name (required):
    Mail (will not be published) (required):
    Website:
    Comment (required):
    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
    验证图片
    刷新验证码
    *

    Popular Articles

      • How to uninstall pc optimizer pro, pc optimizer pro removal 1139 comment(s)
      • what is Pbupdate.exe and how to fix Pbupdate.exe error? 1138 comment(s)

    latest comments

    • 正在加载...

    Tags

      Antivirus Suite Autorun ave.exe Backdoor Backdoor.Win32 Backdoor.Win32 removal browser home page was altered cc Clicker.dj Clunky Backdoor removal Default home page is modified DLL files error DOMDocument->load() downloader encountered Fix Kernel32 Dll Error MAC Microsoft Security Essentials PSW PSW.Kykymber.cc registry was modified remove MyWinLocker remove regedit32.exe remove safedrv.exe remove Trojan.Win32.Buzus.a Run command slow computer Speed Up Computer speed up pc Trojan Trojan-Downloader.Win32.Small.b removal Trojan-PSW.Win32 Trojan.Win32 Trojan.Win32 removal Trojan Downloader Trojan Dropper uninstall MyWinLocker variant dj Virus W32.Cervivec.A@mm Win32 Win32.Hack.GrayBird.al.761856 Win32.TrojDownloader.Guupk.ps Worm Worm.Win32

    Category

    • News
    • Others
    • Registry
    • Script
    • System Utility
    • Virus
    • Windows
    • XML

    Archives

    • December 2011
    • November 2011
    • October 2011
    • September 2011
    • July 2011
    • June 2011
    • May 2011
    • April 2011
    • March 2011
    • February 2011

    Links

    • Download Drivers

    Pages

    • Regtweaker
    • Spyware Cease
    
    Copyright © 2012 PC solutions. Powered by VersionHunter.com. registry repair |Threats Center
    Top