<span> 1</span> <span>php
</span><span> 2</span><span>set_time_limit</span>(0<span>);
</span><span> 3</span><span> 4</span><span>
$ip
</span> =
'127.0.0.1'
<span>;
</span><span> 5</span><span>
$port
</span> = 8888<span>;
</span><span> 6</span><span> 7</span><span>
</span><span> 9</span><span>
echo
</span>
'create fail:'
.<span> socket_strerror(socket_last_error());
</span><span>10</span><span>}
</span><span>11</span><span>12</span><span>
</span><span>14</span><span>
echo
</span>
'bind fail:'
.<span> socket_strerror(socket_last_error());
</span><span>15</span><span>}
</span><span>16</span><span>17</span><span>
</span><span>19</span><span>
echo
</span>
'listen fail:'
.<span> socket_strerror(socket_last_error());
</span><span>20</span><span>}
</span><span>21</span><span>22</span><span>
$count
</span> = 0<span>;
</span><span>23</span><span>24</span><span>
do
</span><span>{
</span><span>25</span><span>
</span><span>27</span><span>28</span><span>
echo
</span>
'accept fail:'
.<span> socket_strerror(socket_last_error());
</span><span>29</span><span>30</span><span>
break
</span><span>;
</span><span>31</span> } <span>
else
</span><span> {
</span><span>32</span><span>33</span><span>
</span><span>35</span> socket_write(<span>
$msgsock
</span>, <span>
$msg
</span>, <span>
strlen
</span>(<span>
$msg
</span><span>));
</span><span>36</span><span>37</span><span>38</span><span>
</span><span>40</span><span>
$buf
</span> = socket_read(<span>
$msgsock
</span>, 8192<span>);
</span><span>41</span><span>42</span><span>43</span><span>
$talkback
</span> =
'receive client: '
. <span>
$buf
</span><span>;
</span><span>44</span><span>
echo
</span><span>
$talkback
</span><span>;
</span><span>45</span><span>46</span><span>47</span><span>
if
</span> (<span>
$count
</span> >= 5<span>) {
</span><span>48</span><span>
break
</span><span>;
</span><span>49</span><span> }
</span><span>50</span><span> }
</span><span>51</span><span>52</span><span>
</span><span>54</span><span>55</span> }<span>
while
</span>(<span>true</span><span>);
</span><span>56</span><span>57</span><span>