"PHP" / Говнокод #19684 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
<?php
  header('Content-Type: text/plain;'); //Мы будем выводить простой текст
  set_time_limit(0); //Скрипт должен работать постоянно
  ob_implicit_flush(); //Все echo должны сразу же отправляться клиенту
  $address = 'localhost'; //Адрес работы сервера
  $port = 1985; //Порт работы сервера (лучше какой-нибудь редкоиспользуемый)
  if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
    //AF_INET - семейство протоколов
    //SOCK_STREAM - тип сокета
    //SOL_TCP - протокол
    echo "Ошибка создания сокета";
  }
  else {
    echo "Сокет создан\n";
  }
  //Связываем дескриптор сокета с указанным адресом и портом
  if (($ret = socket_bind($sock, $address, $port)) < 0) {
    echo "Ошибка связи сокета с адресом и портом";
  }
  else {
    echo "Сокет успешно связан с адресом и портом\n";
  }
  //Начинаем прослушивание сокета (максимум 5 одновременных соединений)
  if (($ret = socket_listen($sock, 5)) < 0) {
    echo "Ошибка при попытке прослушивания сокета";
  }
  else {
    echo "Ждём подключение клиента\n";
  }
  do {
    //Принимаем соединение с сокетом
    if (($msgsock = socket_accept($sock)) < 0) {
      echo "Ошибка при старте соединений с сокетом";
    } else {
      echo "Сокет готов к приёму сообщений\n";
    }
    $msg = "Hello!"; //Сообщение клиенту
    echo "Сообщение от сервера: $msg";
    socket_write($msgsock, $msg, strlen($msg)); //Запись в сокет
    //Бесконечный цикл ожидания клиентов
    do {
      echo 'Сообщение от клиента: ';
      if (false === ($buf = socket_read($msgsock, 1024))) {
        echo "Ошибка при чтении сообщения от клиента";       }
      else {
        echo $buf."\n"; //Сообщение от клиента
      }
      //Если клиент передал exit, то отключаем соединение
      if ($buf == 'exit') {
        socket_close($msgsock);
        break 2;
      }
      if (!is_numeric($buf)) echo "Сообщение от сервера: передано НЕ число\n";
      else {
        $buf = $buf * $buf;
        echo "Сообщение от сервера: ($buf)\n";
      }
      socket_write($msgsock, $buf, strlen($buf));
    } while (true);
  } while (true);
  //Останавливаем работу с сокетом
  if (isset($sock)) {
    socket_close($sock);
    echo "Сокет успешно закрыт";
  }
?>

Запостил: HiNeX HiNeX, (Updated )

Комментарии (62) RSS

  • Сервер на низкоуровневых сокетах, написанный на "php"? Месье знает толк.
    Ответить
  • wh0cd388473 <a href=http://diclofenac.us.com/>diclofenac mail order</a> <a href=http://albendazole2016.us.com/>albendazole</a> <a href=http://buyazithromycin.us.com/>buy azithromycin</a>
    Ответить
  • wh0cd442835 <a href=http://proscar.sexy/>proscar tablets</a> <a href=http://celexa.fail/>celexa</a> <a href=http://wellbutrin.world/>wellbutrin xl 300 mg</a> <a href=http://levaquin.shop/>levofloxacin</a>
    Ответить
  • wh0cd757674 <a href=http://doxycycline5.top/>vibramycin</a> <a href=http://celebrex50.top/>celebrex international pharmacy no prescription</a> <a href=http://citalopram2011.us/>additional reading</a> <a href=http://kamagra3.us/>kamagra soft</a> <a href=http://buytadalafil250.us/>tadalafil 20 mg</a> <a href=http://suhagra6.gdn/>suhagra</a> <a href=http://buyadvair2017.us/>advair</a> <a href=http://adalat12.top/>generic adalat</a>
    Ответить
  • wh0cd18143 <a href=http://clomid.sexy/>clomid</a> <a href=http://levaquin.desi/>levaquin tablets</a> <a href=http://clindamycin.systems/>clindamycin</a>
    Ответить
  • wh0cd474556 <a href=http://zoloft.photography/>zoloft</a> <a href=http://doxycycline.city/>recommended site</a> <a href=http://erythromycin.desi/>erythromycin</a>
    Ответить
  • wh0cd909440 <a href=http://buyzithromax-9.top/>zithromax online pharmacy</a> <a href=http://buyprozac15.top/>buy prozac</a> <a href=http://buytretinoin1.top/>buy tretinoin</a> <a href=http://buycipro0.top/>buy cipro</a> <a href=http://provera2017.top/>provera</a> <a href=http://benicar911.gdn/>benicar</a> <a href=http://triamterene7.us/>triamterene</a>
    Ответить
  • wh0cd266185 <a href=http://buyclonidine2010.top/>clonidine hcl for sleeping</a> <a href=http://neurontin2010.top/>neurontin</a> <a href=http://buytrazodone2011.top/>buy trazodone</a> <a href=http://buyaugmentin2.gdn/>generic augmentin online</a> <a href=http://buyproscar-365.top/>proscar</a>
    Ответить
  • wh0cd670472 <a href=http://buylasix247.top/>lasix</a> <a href=http://synthroid-0.top/>synthroid</a> <a href=http://buycafergot2012.top/>view</a> <a href=http://tadalafil2010.top/>tadalafil</a> <a href=http://sildenafil25.top/>find out more</a>
    Ответить
  • wh0cd626313 <a href=http://buysynthroid25.top/>synthroid</a> <a href=http://buylevitra-4.top/>levitra</a> <a href=http://ventolin20.top/>ventolin</a> <a href=http://levitra1.gdn/>levitra</a> <a href=http://zoloft-0.gdn/>zoloft</a> <a href=http://seroquel-6.gdn/>seroquel</a> <a href=http://buyrevia4.gdn/>revia</a>
    Ответить
  • wh0cd104223 <a href=http://hydrochlorothiazide24.us.org/>check out your url</a> <a href=http://viagrasoft24.us.org/>viagra soft tabs</a> <a href=http://erythromycin24.us.org/>Buy Erythromycin</a>
    Ответить
  • wh0cd918522 <a href=http://cymbaltageneric.us.com/>cymbalta mastercard</a> <a href=http://medroxyprogesterone.us.com/>buy medroxyprogesterone</a> <a href=http://atarax247.us.com/>atarax</a>
    Ответить
  • wh0cd202747 <a href=http://buyneurontin.us.org/>Buy Neurontin</a> <a href=http://buyelimite.biz/>elimite cream 5</a> <a href=http://revatio.us.com/>revatio</a> <a href=http://ordercialis.us.com/>cialis online</a> <a href=http://cialiscost.us.org/>purchase cialis</a>
    Ответить
  • wh0cd181225 <a href=http://buyrobaxin7.top/>buy robaxin</a> <a href=http://buyrobaxin12.top/>robaxin</a> <a href=http://tadalafil1.top/>generic tadalafil</a> <a href=http://cipro2014.top/>cipro</a> <a href=http://atarax2013.gdn/>look at this</a> <a href=http://buysuhagra15.gdn/>suhagra without prescription</a> <a href=http://propranolol4.top/>propranolol</a>
    Ответить
  • wh0cd766769 <a href=http://tamoxifen365.us.com/>nolvadex</a> <a href=http://bactroban2017.us.com/>bactroban</a> <a href=http://silagra.us.com/>Silagra</a>
    Ответить
  • wh0cd659153 <a href=http://buyzoloft.us.com/>buy zoloft</a> <a href=http://sildenafil247.us.org/>Sildenafil 100mg</a>
    Ответить
  • wh0cd299029 <a href=http://deltasone.us.com/>deltasone</a> <a href=http://advairdiskus24.us.org/>advair inhaler</a>
    Ответить
  • wh0cd311468 <a href=http://albuterol-8.gdn/>generic albuterol inhaler</a> <a href=http://buyavana2012.top/>avana</a> <a href=http://buyindocin-2016.top/>buy indocin</a> <a href=http://adalat2010.top/>adalat</a> <a href=http://buyflagyl365.gdn/>buy flagyl</a> <a href=http://buyeurax365.top/>buy eurax</a> <a href=http://buyprednisone20.top/>prednisone</a> <a href=http://kamagra3.top/>kamagra</a>
    Ответить
  • wh0cd15903 <a href=http://amoxicillin24.us.org/>cheap amoxicillin</a> <a href=http://augmentin24.us.org/>augmentin</a> <a href=http://synthroid24.us.org/>Synthroid Online</a>
    Ответить
  • wh0cd137070 <a href=http://zetia.us.com/>BUY ZETIA</a> <a href=http://plaquenil.us.com/>more helpful hints</a>
    Ответить
  • wh0cd496068 <a href=http://vardenafil365.top/>cheap vardenafil</a> <a href=http://revia16.gdn/>revia</a> <a href=http://triamterene-1.gdn/>triamterene 37.5mg hctz 25mg tabs</a> <a href=http://zoloft100.top/>zoloft</a> <a href=http://buyneurontin100.gdn/>buy neurontin</a> <a href=http://buypropecia-0.top/>buy propecia canada</a> <a href=http://buyseroquel2014.top/>seroquel</a> <a href=http://buyneurontin-365.top/>buy neurontin</a>
    Ответить
  • wh0cd691988 <a href=http://propecia247.gdn/>propecia</a> <a href=http://provera2016.top/>provera cost</a> <a href=http://vpxl-247.gdn/>vpxl</a> <a href=http://clomid2015.gdn/>cheap clomid</a>
    Ответить
  • wh0cd440585 <a href=http://buyavana7.top/>avana</a> <a href=http://buyamoxicillin4.top/>buy amoxicillin</a> <a href=http://bentyl25.gdn/>bentyl 20 mg price</a> <a href=http://buycephalexin2017.top/>cephalexin monohydrate</a> <a href=http://buyretina-0.top/>buy retin-a</a> <a href=http://buyampicillin15.top/>buy ampicillin</a>
    Ответить
  • wh0cd896997 <a href=http://ventolin2013.top/>ventolin inhaler</a> <a href=http://buyatenolol4.top/>atenolol 25 mg</a> <a href=http://buyrimonabant10.gdn/>rimonabant</a> <a href=http://buyventolin-5.top/>buy ventolin</a> <a href=http://buydoxycycline0.top/>buy doxycycline no prescription</a> <a href=http://buyanafranil0.gdn/>click for source</a> <a href=http://buyalbendazole17.top/>buy albendazole</a>
    Ответить
  • wh0cd505159 <a href=http://robaxin.us.com/>robaxin with no script</a> <a href=http://levitraonline.us.com/>levitra 40 mg pay with mastercard</a> <a href=http://hydrochlorothiazide24.us.org/>hydrochlorothiazide 25 mg for sale</a> <a href=http://baclofen2.us/>baclofen cost</a>
    Ответить
  • wh0cd115546 <a href=http://buyhydrochlorothiazide2013.top/>buy hydrochlorothiazide online</a> <a href=http://buytetracycline17.top/>buy tetracycline online without prescription</a> <a href=http://buycrestor911.gdn/>buy crestor</a> <a href=http://buycafergot2012.top/>cafergot</a> <a href=http://zithromax11.top/>zithromax 250mg</a> <a href=http://vardenafil365.top/>cheap vardenafil</a> <a href=http://buylevitra11.gdn/>buy levitra</a>
    Ответить
  • wh0cd963805 <a href=http://buyeloconcream.us.com/>elocon for eczema</a> <a href=http://cialisonline.us.com/>cialis online</a> <a href=http://buycrestor.us.org/>crestor online</a> <a href=http://baclofen2016.us.com/>baclofen pills</a> <a href=http://onlinecrestor.us.com/>Generic Crestor</a>
    Ответить
  • wh0cd7943 <a href=http://viagra24.us.org/>Viagra</a> <a href=http://costofviagra247.us.org/>Viagra NO Prescription</a>
    Ответить
  • wh0cd735050 <a href=http://proscar.us.org/>proscar without a prescription</a> <a href=http://glucotrol.us.com/>Glucotrol No Rx</a> <a href=http://buysildalis.us.com/>Buy Sildalis</a> <a href=http://lasix3.us/>lasix</a>
    Ответить

Добавить комментарий

Помни, guest, за тобой могут следить!

    А не использовать ли нам bbcode?


    8