c web service
来源:互联网 发布:spss软件怎么输入数据 编辑:程序博客网 时间:2024/06/07 00:09
转自 http://blog.163.com/wzbwzb_187/blog/static/6632425720106424158919/
以下是源代码:
/**************filename: Server.cpp****************
该程序通过标准socket实现简单Http服务器
运行该服务器可以通过浏览器访问服务器目录下的
Html文件和jpg图片 完成初步的Http服务器功能
***************************************************/
***************************************************/
#include <winsock.h>
#include <sys/stat.h>
#include <iostream>
using namespace std;
#include <sys/stat.h>
#include <iostream>
using namespace std;
#define SERVER_PORT 10000 //自定义的服务端口
#define HOSTLEN 256 //主机名长度
#define BACKLOG 10 //同时等待的连接个数
#define HOSTLEN 256
#define BACKLOG 10
/**************************************
该方法包装了send()
通过该方法发送数据 能够全部发出
没有遗漏
**************************************/
int sendall(int s, char *buf, int *len) {
int total = 0; // 已经发送字节数
int bytesleft = *len; //还剩余多少字节
int n;
while(total < *len) {
n = send(s, buf+total, bytesleft, 0);
if (n == -1) { break; }
total += n;
bytesleft -= n;
}
*len = total; // 返回实际发送出去的字节数
return n==-1?-1:0; // 成功发送返回0 失败-1
}
**************************************/
int sendall(int s, char *buf, int *len) {
}
/**************************************
该方法处理错误请求
并向客户端发送错误信息
**************************************/
void wrong_req(int sock) {
char* error_head = "HTTP/1.0 501 Not Implemented\r\n"; //输出501错误
int len = strlen(error_head);
if (sendall(sock, error_head, &len) == -1) { //向客户发送
printf("Sending failed!");
return;
}
**************************************/
void wrong_req(int sock) {
}
/**********************************
该方法判断用户请求的文件是否存在
不存在返回true 存在返回false
***********************************/
bool not_exit(char* arguments) {
struct stat dir_info;
return (stat(arguments, &dir_info) == -1);
}
***********************************/
bool not_exit(char* arguments) {
}
/*************************************
所请求的文件不存在
*************************************/
void file_not_found(char* arguments, int sock) {
*************************************/
void file_not_found(char* arguments, int sock) {
}
/*************************************
发送Http协议头部信息
其中包括响应类型和Content Type
*************************************/
void send_header(int send_to, char* content_type) {
char* head = "HTTP/1.0 200 OK\r\n"; //正确的头部信息
int len = strlen(head);
if (sendall(send_to, head, &len) == -1) { //向连接的客户端发送数据
printf("Sending error");
return;
}
*************************************/
void send_header(int send_to, char* content_type) {
}
/***********************************
取得用户所请求的文件类型
即文件后缀 (.html .jpg .gif)
************************************/
char* file_type(char* arg) {
char * temp; //临时字符串指针
if ((temp=strrchr(arg,'.')) != NULL) { //取得后缀
return temp+1;
}
return ""; //如果请求的文件名中没有. 则返回空串
}
************************************/
char* file_type(char* arg) {
}
/*************************************
该方法为程序核心
负责真正发送文件 如*.html *.jpg等
*************************************/
void send_file(char* arguments, int sock) {
*************************************/
void send_file(char* arguments, int sock) {
}
/***********************************
解析并处理用户请求
***********************************/
void handle_req(char* request, int client_sock) {
***********************************/
void handle_req(char* request, int client_sock) {
}
/*************************************
该方法构造服务器端的SOCKET
返回构造好的socket描述符
*************************************/
int make_server_socket() {
struct sockaddr_in server_addr; //服务器地址结构体
*************************************/
int make_server_socket() {
}
/***********************
主函数main()
程序入口
***********************/
void main(int argc, char * argv[]) {
***********************/
void main(int argc, char * argv[]) {
}
/**************程序结束Server.cpp******************/
0 0
- C实现web service
- c web service
- C#:Web Service异常处理
- C#利用Web Service实现短信发送
- c++Web Service的简单例子
- Delphi 调用.NET(C#) Web Service
- linux c 实现 xml web service
- Objective-C调用Web Service示例
- gsoap 实现 C/C++ 调用web service
- C#(C/s,B/s)程序里使用web service
- 如何创建、发布Web Service和 C#WINFORM里如何调用WEB Service API
- 如何创建、发布Web Service和 C#WINFORM里如何调用WEB Service API
- 如何创建、发布Web Service和 C#WINFORM里如何调用WEB Service API
- 如何创建、发布Web Service和 C#WINFORM里如何调用WEB Service API (分享)
- 如何创建、发布Web Service和 C#WINFORM里如何调用WEB Service API
- 如何创建、发布Web Service和 C#WINFORM里如何调用WEB Service API
- Web Service
- Web Service
- Eclipse安装Maven插件
- TQIMX6Q学习笔记——U-Boot移植
- Web APP开发技巧总结
- 第二章 反向传播算法如何工作的?
- java和c语言的switch语句支持哪些数据类型
- c web service
- 多线程之传统多线程
- linux下查看网卡信息的命令
- Canny边缘检测算法原理及其VC实现详解(一)
- 四个变量比较大小
- jq 异步提交文件
- UITabBarController点击UITabBarItem 禁止跳转ViewController
- mac和window下的html开发工具
- SQLite字符串拼接