socket
Moderators: mindphp, ผู้ดูแลกระดาน
- mindphp
- ผู้ดูแลระบบ MindPHP
- Posts: 26573
- Joined: 22/09/2008 6:18 pm
- Contact:
รับ ส่ง ผ่าน โปรโตคอล อะไรครับ
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
- mindphp
- ผู้ดูแลระบบ MindPHP
- Posts: 26573
- Joined: 22/09/2008 6:18 pm
- Contact:
ลองดูที่นี่ครับ
http://www.devshed.com/c/a/PHP/Socket-P ... -With-PHP/
แนะนำให้ ลอง เขียน และ รันเป็น php-cli
http://www.devshed.com/c/a/PHP/Socket-P ... -With-PHP/
แนะนำให้ ลอง เขียน และ รันเป็น php-cli
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
- shutup
- PHP Newbie
- Posts: 5
- Joined: 01/01/1970 7:00 am
- mindphp
- ผู้ดูแลระบบ MindPHP
- Posts: 26573
- Joined: 22/09/2008 6:18 pm
- Contact:
โค้ด ยังไงครับ ที่ เกิด error ขึ้น
ส่วนการรับ ค่า การโพส มา ต้องเกี่ยว กับค่ำสั่งขอ OS ที่เราใช้นะครับ ที่ใช้ตรวจสอบ ว่ามีใครติดต่อง ผ่าน protocol อะไร เข้ามา
ส่วนการรับ ค่า การโพส มา ต้องเกี่ยว กับค่ำสั่งขอ OS ที่เราใช้นะครับ ที่ใช้ตรวจสอบ ว่ามีใครติดต่อง ผ่าน protocol อะไร เข้ามา
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
- shutup
- PHP Newbie
- Posts: 5
- Joined: 01/01/1970 7:00 am
<?php
error_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting
* as it comes in. */
ob_implicit_flush();
$address = '192.168.1.53';
$port = 10000;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
echo "socket_create() failed: reason: " . socket_strerror($sock) . "\n";
}
if (($ret = socket_bind($sock, $address, $port)) < 0) {
echo "socket_bind() failed: reason: " . socket_strerror($ret) . "\n";
}
if (($ret = socket_listen($sock, 5)) < 0) {
echo "socket_listen() failed: reason: " . socket_strerror($ret) . "\n";
}
do {
if (($msgsock = socket_accept($sock)) < 0) {
echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n";
break;
}
/* Send instructions. */
$msg = "\nWelcome to the PHP Test Server. \n" .
"To quit, type 'quit'. To shut down the server type 'shutdown'.\n";
socket_write($msgsock, $msg, strlen($msg));
do {
if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
echo "socket_read() failed: reason: " . socket_strerror($ret) . "\n";
break 2;
}
if (!$buf = trim($buf)) {
continue;
}
if ($buf == 'quit') {
break;
}
if ($buf == 'shutdown') {
socket_close($msgsock);
break 2;
}
$talkback = "PHP: You said '$buf'.\n";
socket_write($msgsock, $talkback, strlen($talkback));
echo "$buf\n";
} while (true);
socket_close($msgsock);
} while (true);
socket_close($sock);
?>
ประมาณนี้อ่ะครับ
error_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting
* as it comes in. */
ob_implicit_flush();
$address = '192.168.1.53';
$port = 10000;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
echo "socket_create() failed: reason: " . socket_strerror($sock) . "\n";
}
if (($ret = socket_bind($sock, $address, $port)) < 0) {
echo "socket_bind() failed: reason: " . socket_strerror($ret) . "\n";
}
if (($ret = socket_listen($sock, 5)) < 0) {
echo "socket_listen() failed: reason: " . socket_strerror($ret) . "\n";
}
do {
if (($msgsock = socket_accept($sock)) < 0) {
echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n";
break;
}
/* Send instructions. */
$msg = "\nWelcome to the PHP Test Server. \n" .
"To quit, type 'quit'. To shut down the server type 'shutdown'.\n";
socket_write($msgsock, $msg, strlen($msg));
do {
if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
echo "socket_read() failed: reason: " . socket_strerror($ret) . "\n";
break 2;
}
if (!$buf = trim($buf)) {
continue;
}
if ($buf == 'quit') {
break;
}
if ($buf == 'shutdown') {
socket_close($msgsock);
break 2;
}
$talkback = "PHP: You said '$buf'.\n";
socket_write($msgsock, $talkback, strlen($talkback));
echo "$buf\n";
} while (true);
socket_close($msgsock);
} while (true);
socket_close($sock);
?>
ประมาณนี้อ่ะครับ
-
- Similar Topics
- Replies
- Views
- Last post
-
- 15 Replies
- 17474 Views
-
Last post by touleg
04/04/2013 1:47 pm
-
-
คือมีเรื่องไม่ค่อยเข้าใจเกี่ยวกับ socket server กับการใช้ ฟังชัน Socket_bind()
by Roboto » 20/06/2011 4:23 pm » in Programming - PHP - 8 Replies
- 2997 Views
-
Last post by Roboto
29/06/2011 10:13 am
-
-
-
วิธีแก้ปัญหา could not open socket plugin reCaptcha ใน joomla 2.5
by mindphp » 03/08/2013 1:13 pm » in Programming - PHP - 0 Replies
- 1695 Views
-
Last post by mindphp
03/08/2013 1:13 pm
-
-
-
เจอปัญหา Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) [2002] บน FreeBSD
by mindphp » 23/07/2017 3:08 am » in Linux - Web Server - 1 Replies
- 1173 Views
-
Last post by mindphp
23/07/2017 3:20 am
-
-
- 4 Replies
- 997 Views
-
Last post by Ittichai_chupol
31/07/2019 1:33 pm
Who is online
Users browsing this forum: Google [Bot] and 10 guests