1 封装函数
1.1 Ohsce_eng_socket_X
1.1.1 Ohsce_eng_socket_client
1.1.2 Ohsce_eng_socket_client_setspace
1.1.3 Ohsce_eng_socket_server
1.1.3.1 Ohsce_eng_socket_server
1.1.3.2 callback
1.1.3.3 callbackaccept
1.1.3.4 fap
1.1.4 Ohsce_eng_socket_send
1.1.5 oibc_sce_socket_recv
1.1.6 Ohsce_eng_socket_server_runtcp
1.1.7 Ohsce_eng_socket_server_runudp
1.1.8 Ohsce_eng_socket_server_close
1.1.9 ohsce_eng_socket_reConnect
1.2 Ohsce_eng_serial_X
1.2.1 Ohsce_eng_serial_creat
1.2.2 Ohsce_eng_serial_setspace
1.2.3 Ohsce_eng_serial_open
1.2.4 Ohsce_eng_serial_write
1.2.5 Ohsce_eng_serial_read
1.2.6 Ohsce_eng_serial_comwr
1.2.7 Ohsce_eng_serial_npcomwr
1.2.8 Ohsce_eng_serial_close
1.3 Ohsce_channel_X
1.3.1 ohsce_channel_server_creat
1.3.2 ohsce_channel_client_creat
1.3.3 ohsce_channel_read
1.3.4 ohsce_channel_write
1.3.5 ohsce_reChannel
1.4 Ohsce_eng_url_X
1.4.1 Ohsce_eng_url_c
1.5 Ohsce_eng_sm_X
1.5.1 Ohsce_eng_sm_creat
1.5.2 Ohsce_eng_sm_open
1.5.3 Ohsce_eng_sm_write
1.5.4 Ohsce_eng_sm_read
1.5.5 Ohsce_eng_sm_close
1.6 Ohsce_OTHERS
1.6.1 Ohsce_base_iota
1.6.2 Ohsce_base_iota_set
2 基础函数
2.1 Ohsce_getos
2.2 ohsce_mcrypt
2.3 Ohsce_createSocket
2.4 Ohsce_geterror
2.5 Ohsce_socketconnect
2.6 Ohsce_socketclose
2.7 Ohsce_socketstop
2.8 Ohsce_socketbind
2.9 Ohsce_socketsetbuff
2.10 Ohsce_fastpush
2.11 Ohsce_socketlisten
2.12 Ohsce_getflags
2.13 Ohsce_socketsend
2.14 Ohsce_socketwrite
2.15 Ohsce_socketrecv
2.16 Ohsce_socketrecvfrom
2.17 Ohsce_socketread
2.18 Ohsce_casepr
2.19 Ohsce_comparity
2.20 Ohsce_comfc
2.21 Ohsce_comset
2.22 Ohsce_comecase
2.23 Ohsce_comopen
2.24 Ohsce_comread
2.25 Ohsce_comwrite
2.26 Ohsce_comwriteread_np
2.27 Ohsce_ReadCom
2.28 Ohsce_fastflush
2.29 Ohsce_getbaud
2.30 Ohsce_comclose
2.31 Ohsce_ccom
2.32 Ohsce_exec
2.33 ohsce_smCreat
2.34 ohsce_smDecode
2.35 ohsce_smEncode
2.36 ohsce_smWrite
2.37 ohsce_smRead
2.38 ohsce_smClose
2.39 ohsce_smDelete
2.40 ohsce_smClean
2.41 ohsce_comflush
2.42 Ohsce_makearp
2.43 Ohsce_url_c
2.44 Ohsce_url_cp
2.45 Ohsce_url_seturl
2.46 Ohsce_url_setmode
2.47 Ohsce_url_setpos
2.48 Ohsce_url_setjson
2.49 Ohsce_url_setcookie
2.50 Ohsce_url_setproxy
2.51 Ohsce_url_setftp
2.52 Ohsce_url_exec
2.53 Ohsce_url_close
2.54 ohsce_jsonrpc_client_creat
2.55 ohsce_jsonrpc_format_response
2.56 ohsce_jsonrpc_request

Ohsce_eng_socket_server

2016-09-01 16:37:00
admin
4214
最后编辑:admin 于 2016-10-17 11:10:04
简介:创建一个Socket_Server可用资源。

(OHSCE >=V0.1.9)-创建一个Socket_Server 可用资源。

Ohsce_eng_socket _server(&$ohsceserver,$protocol,$port,$ip=null,$callback,$callbackaccept=null,$AF='ipv4',$sync=true,$mode='defalut',$max=null)


$ohsceserver

   -返回资源 (Array)

$protocol

    -协议 TCPUDP 、ICMP (String)

$port

    -本机端口 (INT)

$ip

    -本机IP (String)

$AF

    -IPV4/IPV6 (String)

$sync

    -是否同步/异步 (bool)

$callback

    -收到客户端信息时的回调函数名称 (String)(v0.1.X)

    -回调函数、新客户到访函数、循环内常驻函数集(>v0.1.22)

  array('callback'=>'comservera','accept'=>'comserveraccept','fap'=>'comserveralways')

  意为:回调函数为 comservera() 新客户端到访函数为 comserveraccept() 循环内常驻函数为 comserveralways()

$callbackaccept

    -新客户端到访时的回调函数名称 (String)(v0.1.x)

$mode

    -模式(预建变量集)若要完全自定义参数请使用OHSCE基础函数集建立.

$max

    -最大承载数量

Example:

<?php
function example(&$socket,$buf,$len,$zv){  //收到数据时的回调函数
	echo $buf;
	Ohsce_socketwrite($socket,'hi '.$buf);
	return true;
}
function exampleaccept(&$socket,$ip,$port,$zv){  //新客户端到访时的回调函数
	Ohsce_socketwrite($socket,'Welcome'.$ip.':'.$port);
	return true;
}
Ohsce_eng_socket_server($ohsceserver,'tcp',7626,'127.0.0.1','example','exampleaccept');//创建一个TCP服务端资源 绑定127.0.0.1:7626 并传入回调函数
Ohsce_eng_socket_server_runtcp($ohsceserver); //开始运行

NOTICE:

如果是端口与资源的绑定会自动进行。