資源簡介
分別用UDP、TCP、多線程通信三種方式實現socket編程,是學習socket編程最全的小項目,是linux高級編程學習必須部分,現在我工作基本天天都跟他們打交道
代碼片段和文件信息
#include
#include
#include
#include
#include
#include
#define?BUF_SIZE?1024
char?buf[BUF_SIZE];
pthread_mutex_t?work_mutex;
void?*read_fun(void?*arg);
void?*write_fun(void?*arg);
int?main()
{
??int?res;
??pthread_t?rd_threadwr_thread;
??res=pthread_mutex_init(&work_mutexNULL);
??if(0!=res)
????{
??????perror(“Mutex?inital?failed\n“);
??????return?-1;
????}
??res=pthread_create(&rd_threadNULL(void*)read_funNULL);
??if(0!=res)
????{
??????perror(“thread?create?failed\n“);
??????return?-1;
????}
??res=pthread_create(&wr_threadNULL(void*)write_funNULL);
??if(0!=res)
????{
??????perror(“thread?create?failed\n“);
??????return?-1;
????}
??pthread_join(wr_threadNULL);
}
void?*read_fun(v
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????13080??2010-05-27?16:48??socket\pthread_rw
?????文件???????1028??2010-05-27?16:48??socket\pthread_rw.c
?????文件??????16384??2010-05-25?20:41??socket\socket_tcp\.service3.c.swp
?????文件???????1231??2010-05-25?12:53??socket\socket_tcp\client.c
?????文件???????7900??2010-05-27?09:51??socket\socket_tcp\client_3
?????文件???????3442??2010-05-25?16:05??socket\socket_tcp\client_3.c
?????文件???????1523??2010-05-25?12:53??socket\socket_tcp\service.c
?????文件???????8720??2010-05-27?09:50??socket\socket_tcp\service_3
?????文件???????4690??2010-05-27?09:50??socket\socket_tcp\service_3.c
?????文件??????15382??2010-05-31?12:15??socket\socket_udp\client_2
?????文件???????5203??2010-05-31?12:21??socket\socket_udp\client_2.c
?????文件??????16381??2010-05-31?12:01??socket\socket_udp\service_2
?????文件???????6685??2010-05-31?12:01??socket\socket_udp\service_2.c
?????目錄??????????0??2010-11-13?11:06??socket\socket_tcp
?????目錄??????????0??2010-11-13?11:06??socket\socket_udp
?????目錄??????????0??2010-11-13?11:06??socket
-----------?---------??----------?-----??----
???????????????101649????????????????????16
評論
共有 條評論