所以.我正在尝试创建一个从服务器检索.html文件的C应用程序,例如www.example.com.为此,我使用套接字connect send和recv方法.我的实现看起来像这样:
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main(void) {
//Stream sockets and rcv()
struct addrinfo hints, *res;
int sockfd;
char buf[2056];
int byte_count;
//get host info, make socket and connect it
memset(&hints, 0,sizeof hints);
hints.ai_family=AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
getaddrinfo("www.example.com","80", &hints, &res);
sockfd = socket(res->ai_family,res->ai_socktype,res->ai_protocol);
printf("Connecting...\n");
connect(sockfd,res->ai_addr,res->ai_addrlen);
printf("Connected!\n");
char *header = "GET /index.html HTTP/1.1\nHost: www.example.com\n";
send(sockfd,header,sizeof header,0);
printf("GET Sent...\n");
//all right ! now that we're …Run Code Online (Sandbox Code Playgroud) 我只是想知道是否有办法:((a b))"进入" '((a b)).
我使用
(symbol->string "((a b))")哪个给了我'|((a b))|
这不完全是我需要的.我需要一份清单.
所以我正在做理发店问题,但现在我想让它"视觉化"和网络友好.当服务器启动时,等待客户端连接,每次客户端连接时都会绘制一个"P",它在屏幕上传播到理发位置.我和NCurses这样做,我没有问题.
但是我一次只设法绘制一个客户端(一个'P').我想在屏幕上看到很多客户端('P').因为我现在拥有它的方式我一次只使用1把椅子,然后客户端被出席并退出,然后accept()队列中的下一个客户端进入屏幕,依此类推.它给人的印象是没有实际的共识.
我有一个非常宽松的代码但叉/插座部分在这里:
pid_t client;
int p;
RandSeed=8;
listen(connection,90);
while(1){
remote_dir_size = sizeof(remote_dir);
//"Awaiting connection...
if((connection_client=accept(connection,(struct sockaddr *)&remote_dir,&remote_dir_size))<0){
console_write("CONNECTION REJECTED!");
exit(-1);
}
//"Connection accepted!
client=fork();
switch(client)
{
case -1:
console_write("Error Forking!!");
exit(1);
case 0:
close(connection); //So that another client can come.
recvs = recv(connection_client,petition,sizeof(petition),0);
//console_write(petition);
// console_write(" moviendose.");
move_client();
//Check for avialable chairs
//waiting_client_count++;
sem_wait(waitingRoom); //wait until available
move_client_to_chairs();
sitting_client_count++;
redraw_chairs(); //redraw chair <--Useless since only 1 chair is used at a time :/
//waiting for barber
sem_wait(barberChair);
//barber available, …Run Code Online (Sandbox Code Playgroud)