关于SOCKET的问题,如何安装socket server,如何启动 socket server,具体的配置是怎么样的?

wangjinzhai 2003-09-26 09:30:08
关于SOCKET的问题,如何安装socket server,如何启动 socket server,具体的配置是怎么样的?
我现在是在windows 2000上,iis,php_sockets.dll和php_w32api.dll加载了
其他还要注意什么呢?

<?php
/*
* We don't want any time-limit for how the long can hang
* around, waiting for connections:
*/
set_time_limit(0);

/* Create a new socket: */
if( ($sock = socket( AF_INET, SOCK_STREAM, 0 )) < 0 )
{
print strerror( $sock ) . "\n";
exit(1);
}

/* Bind the socket to an address and a port: */
if( ($ret = bind( $sock, "10.31.172.77", 10000 )) < 0 )
{
print strerror( $ret ) . "\n";
exit(1);
}

/*
* Listen for incoming connections on $sock.
* The '5' means that we allow 5 queued connections.
*/
if( ($ret = listen( $sock, 5 )) < 0 )
{
print strerror( $ret ) . "\n";
}

/* Accept incoming connections: */
if( ($msgsock = accept_connect( $sock )) < 0)
{
print strerror( $msgsock ) . "\n";
exit(1);
}

/* Send the welcome-message: */
$message = "Welcome to my TCP-server!\n";
if( ($ret = write( $msgsock, $message, strlen($message)) ) < 0 )
{
print strerror( $msgsock ) . "\n";
exit(1);
}

/* Read/Receive some data from the client: */
$buf = '';
if( ($ret = read( $msgsock, $buf, 128 )) < 0 )
{
print strerror( $ret ) . "\n";
exit(1);
}

/* Echo the received data back to the client: */
if( ($ret = write( $msgsock, "You said: $buf{CONTENT}\n", strlen("You said: $buf{CONTENT}\n")) ) < 0 )
{
print strerror( $ret ) . "\n";
exit(1);
}

/* Close the communication-socket: */
close( $msgsock );

/* Close the global socket: */
close( $sock );
?>
出错信息:
Call to undefined function: socket()
请大虾帮忙,谢谢!
...全文
144 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnpr 2003-09-26
  • 打赏
  • 举报
回复
http://www.eaoo.com/design/list.asp?classid=2&Nclassid=9

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧