php通过socket和c通讯
时间:2006-03-31 来源:php店小二
php和c通过socket通信
/*server.c*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
main(){
int sock;
struct sockaddr_in server,client;
int recvd,snd;
int structlength;
char * server_ip = "128.168.10.1";/*server ip address*/
int port = 8888;
char recvbuf[2000],sendbuf[2000];
char str1[]="I have received: ";
memset((char *)&server,0,sizeof(server));
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(server_ip);
server.sin_port = htons(port);
memset((char *)&client,0,sizeof(client));
client.sin_family = AF_INET;
client.sin_addr.s_addr = htonl(INADDR_ANY);
client.sin_port = htons(port);
if((sock = socket (AF_INET,SOCK_DGRAM,0))
/*这个过程很简单,就是客户端提交一个信息,服务端接收,
并返回给客户端一个"接收到"的确认信息。
*/
/*server.c*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
main(){
int sock;
struct sockaddr_in server,client;
int recvd,snd;
int structlength;
char * server_ip = "128.168.10.1";/*server ip address*/
int port = 8888;
char recvbuf[2000],sendbuf[2000];
char str1[]="I have received: ";
memset((char *)&server,0,sizeof(server));
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(server_ip);
server.sin_port = htons(port);
memset((char *)&client,0,sizeof(client));
client.sin_family = AF_INET;
client.sin_addr.s_addr = htonl(INADDR_ANY);
client.sin_port = htons(port);
if((sock = socket (AF_INET,SOCK_DGRAM,0))
/*这个过程很简单,就是客户端提交一个信息,服务端接收,
并返回给客户端一个"接收到"的确认信息。
*/
相关阅读 更多 +