我正在寻找一种进行更灵活的套接字通信的方法。
代码形式的外部链接工作正常,但是问题是当我第二次运行“客户端”程序的2个或更多实例时,下一个实例必须等到上一个实例完成与“服务器”的通信。我该如何解决?
对不起我的英语和外部链接不好,但我不知道如何在此处添加正确缩进的代码。
https://www.dropbox.com/s/38rxvghroqaxuci/mix.c?dl=0
最诚挚的问候。
修改是您发布代码的方式
服务器
RewriteEngine On
# To externally redirect with pid
RewriteCond %{THE_REQUEST} \s/+spares/\?pid=(.*)\s [NC]
RewriteRule ^ /spares/%1 [R=301,L,NE]
# To internally rewrite to ?pid=
RewriteCond %{QUERY_STRING} pid=(.+)$
RewriteRule ^spares/$ /spares/?pid=%1 [NC,L]
客户代码:
// call socket()
// call bind()
// call listen()
while (1)
{
incomming_connection = accept(uds_dispacher_fd, (struct sockaddr *)&uds_peer_config, &uds_peer_config_len);
while ( (no_of_bytes_read=recv(incomming_connection, uds_input_buffer, UDS_BUFFER_SIZE, 0)) != 0 )
{
if (uds_input_buffer[no_of_bytes_read-2] == '\n')
{
switch (uds_input_buffer[0])
{
case SOME_VARIABLE:
strcpy(buffer, "Hello");
break;
default:
strcpy(buffer, "Wut");
}
}
send(incomming_connection, buffer, strlen(uds_output_buffer),0);
}
}