碼了2個小時多,終於弄完了。用的編輯器是qt creator ,突然發現在qt creator上,也支援這些底層的c語言。在linux上除錯無誤。寫這個,也算是自己讀書的記錄吧!
#include #include #include #include #include #include #include #include #include #define port 1234
#define backlong 100
#define maxcharsize 100
void process_client (int connectfd,struct sockaddr_in client);
void *start_routine(void *arg);
struct arg;
struct arg *arg;
int main(void)
setsockopt(listenfd,sol_socket,so_reuseaddr,&opt,sizeof(opt));
bzero(&server,sizeof(server));
server.sin_family = af_inet;
server.sin_port = htons(port);
server.sin_addr.s_addr= htonl(inaddr_any);
if(bind(listenfd,(struct sockaddr *)&server,sizeof(struct sockaddr)) == -1)
if(listen(listenfd,backlong) == -1)
while(1)
arg = (struct arg *)malloc(sizeof (struct arg));
arg->connfd = connectfd;
memcpy((void *)&arg->client,&client,sizeof(client));
if(pthread_create(&tid,null,start_routine,(void *)arg))
}close(listenfd);
}void *start_routine(void *arg)
void process_client(int connectfd, struct sockaddr_in client)
else if(recvlen < 0)
client_name[recvlen] = '\0';
printf("client name is %s.\n",client_name);
bzero(recvbuf,100);
while(recvlen=recv(connectfd,recvbuf,maxcharsize,0))
{recvbuf[recvlen] = '\0';
printf("receive clent (%s) message:%s\n",client_name,recvbuf);
for(i = 0;i
乙個簡單的多執行緒
頭部 type tmythread class tthread protected procedure execute override end procedure tmythread.execute begin coinitialize nil 如果不加這句,會提示未呼叫coinitialize ...
乙個簡單的Perl多執行緒指令碼
usr bin perl w use strict our max child 20 1 my grp pid getpgrp foreach my item 1.80 grep v grep wc l while p count max child grep v grep wc l chomp p...
C 乙個簡單的多執行緒例子
乙個是窗體 乙個是class 直接上 了,先來窗體的吧。窗體 引入命名空間 using system.threading 完整 namespace threadexample private void btn start click object sender,eventargs e private...