php和c通过socket通信--udp篇
时间:2006-03-22 来源:zming_5000
/*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:\n";
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))
/*这个过程很简单,就是客户端提交一个信息,服务端接收,
并返回给客户端一个"接收到"的确认信息。
*/
相关阅读 更多 +