c语言web服务器编程问题
== INVALID_SOCKET)
fclose(read_from);
HANDLE hThread;
SOCKET ClientSocket=(SOCKET)(LPVOID)lparam;
}
}
#include <stdio.h>
char recvbuf[MAXLINE]="";
}
read_from = fopen(fileName2, "r");
#include<stdlib.h>
{
printf("打开文件错误");
while (!feof(read_from))
c/gif\r\n ";
ServerAddr.sin_port = htons(Port);
closesocket(ListeningSocket);
void main(void)
WSADATA wsaData;
}
关于网友提出的“ c语言web”问题疑问,本网通过在网上对“ c语言web服务器编程问题”有关的相关答案进行了整理,dede标签,供用户进行参考,详细问题解答如下:
描述:我编写一个简易web服务器,dede织梦视频教程,是b/s结构
问题: c语言web服务器编程问题
send(ClientSocket,kang,strlen(kang),0);
if(fileName1[sum-3]=='f'){
if(fileName1[sum-4]='i')
#include "ctype.h"
int sum=0;
if ((ListeningSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))
for(int k=0;k<sum-2;k++)
printf("监听socket初始化错误 %d\n", WSAGetLastError());
printf(fileName2);
{
{
}
if(fileName1[sum-5]=='j')
ServerAddr.sin_addr.s_addr = htonl(INADDR_ANY);
int i=0;
{
return;
if(fileName1[sum-3]=='g'){
j++;
char fileName2[32]="";
== SOCKET_ERROR)
#define MAXLINE 32
send(ClientSocket,content_type,14,0);
}
char* content_type = "text/html\r\n ";
if(recvbuf[i]==' '){
if(recv(ClientSocket,recvbuf,32,0)==SOCKET_ERROR)
SOCKADDR_IN ServerAddr;
char sendbuf[1024]="";
char* head ="HTTP/1.1 200 OK\r\n";
{
if ((NewConnection = accept(ListeningSocket,NULL,NULL)) == INVALID_SOCKET)
int ClientAddrLen;
printf("接受错误");
while(i<strlen(recvbuf))
fileName1[j]=recvbuf[i+2];
}
if(recvbuf[i]==' '&&flag==1)
if(fileName1[sum-4]='p')
WSACleanup();
}
if(!read_from){
return;
}
#include<string.h>
printf("接收错误 %d\n", WSAGetLastError());
}
if(hThread==NULL)
{
}
{
char* kang="Content-Length: \r\nServer:\r\nDate: \r\n<html><head>康</head></html>";
}
flag=1-flag;
{
int flag=1;
send(ClientSocket,head,19,0);
解决方案1:
LZ勇气可嘉, 居然直接用socket.
int j=0;
}
return;
WSACleanup();
WSACleanup();
{
closesocket(ListeningSocket);
SOCKET ListeningSocket;
ServerAddr.sin_family = AF_INET;
if(flag==0)
send(ClientSocket,sendbuf,strlen(sendbuf),0);
if ((Ret = WSAStartup(MAKEWORD(2,2), &wsaData)) != 0)
if (bind(ListeningSocket, (SOCKADDR *)&ServerAddr, sizeof(ServerAddr))
c/jpeg\r\n";
}
代码贴的不是很清晰,没时间细看, 感觉在"<html>"前应再加一个"\r\n"(http response header应用两个\r\n结束).
printf("监听错误 %d\n", WSAGetLastError());
WSACleanup();
int Port = 6789;
fileName2[k]=fileName1[k];
break;
sum++;
DWORD dwThreadId;
SOCKET NewConnection;
{
}
if (listen(ListeningSocket, 5) == SOCKET_ERROR)
}
#include <winsock2.h>
return 0;
{
printf("初始化winsock版本错误 %d\n", Ret);
DWORD WINAPI AnswerThread(LPVOID lparam)
return;
FILE* read_from;
i++;
send(ClientSocket,cent,14,0);
fgets(sendbuf, 1024, read_from);
char fileName1[32]="";
char* cent="Content-Type: ";
closesocket(ListeningSocket);
{
int Ret;
用浏览器连接可以,但是浏览器就是不显示数据,一直在等待,代码如下,请大家帮帮忙
}
if(fileName1[sum-5]=='g')
printf("创建线程错误.\n");
{
while(1)