資源簡介
自己做的小程序,有很多不足,僅供大家參考。

代碼片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define?i?3
char?msg[100];
int?fd;
int?result;
int?fromlen;
int?flag;
int?name2;
int?password2;
int?n;
struct?sockaddr_in?clientserver;
struct?data
{
int?name;
int?password;
struct?sockaddr_in?addr;
}date;
//struct?data?receive[i]={{111222}{333444}{555666}};
struct?land
{
int?name;
int?password;
}lan;
union?users
{
struct?land?lan;
char?msg[100];
}use;
struct?chat
{
int?flag;
union?users?use;
}ch;
int?main()
{
struct?data?receive[i]={{111222}{333444}{555666}};
fd=socket(AF_INETSOCK_DGRAM0);
if?(fd<0)
{
printf(“creat?socket?fail\n“);
exit(-1);
}
int?opt?=?SO_REUSEADDR;
setsockopt(fdSOL_SOCKETSO_REUSEADDR&optsizeof(opt));
server.sin_family?=?AF_INET;
server.sin_port?=?htons(2012);
server.sin_addr.s_addr?=?htonl(INADDR_ANY);
result?=?bind(fd(struct?sockaddr?*)&serversizeof(struct?sockaddr));
if?(result<0)
{
printf(“bind?fail\n“);
}
else
{
printf(“bind?success\n“);
}
fromlen=sizeof(struct?sockaddr);
while(1)
{
result?=?recvfrom(fd&chsizeof(struct?chat)0(struct?sockaddr?*)&client&fromlen);
printf(“%d?%d?%d\n“ch.flagch.use.lan.namech.use.lan.password);
if?(result<0)
{
printf(“recive?fail\n“);
}
else
{
printf(“%d\n“ch.flag);
if?(ch.flag==0)
{
name2=ch.use.lan.name;
password2=ch.use.lan.password;
printf(“%d?%d\n“name2password2);
if?((receive[0].name==name2)&&(receive[0].password==password2))
{
receive[0].addr=client;
ch.flag=1;
result?=?sendto(fd&chsizeof(struct?chat)0(struct?sockaddr*)&clientsizeof(struct?sockaddr));
if?(result<0)
{
printf(“sendto?fail\n“);
exit(-1);
}
//break;
}
else?if?((receive[1].name==name2)&&(receive[1].password==password2))
{
ch.flag=1;
receive[1].addr=client;
result?=?sendto(fd&chsizeof(struct?chat)0(struct?sockaddr*)&clientsizeof(struct?sockaddr));
if?(result<0)
{
printf(“sendto?fail\n“);
exit(-1);
}
break;
}
else?if?((receive[2].name==name2)&&(receive[2].password==password2))
{
ch.flag=1;
receive[2].addr=client;
result?=?sendto(fd&chsizeof(struct?chat)0(struct?sockaddr*)&clientsizeof(struct?sockaddr));
if?(result<0)
{
printf(“sendto?fail\n“);
exit(-1);
}
break;
}
else
{
ch.flag=0;
result?=?sendto(fd&ch.flagsizeof(struct?chat)0(struct?sockaddr*)&clientsizeof(struct?sockaddr));
if?(result<0)
{
printf(“sendto?fail\n“);
exit(-1);
}
}
}
}
}
while(1)
{
//printf(“%d“aton(date.addr.sin_port));
//scanf(“%s“ch.use.msg);
//result?=?sendto(fd&chsizeof(struct?chat)0(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1554??2012-08-23?16:08??QTqq\qq\chat.cpp
?????文件????????723??2012-08-23?15:59??QTqq\qq\chat.h
?????文件?????315080??2012-08-23?16:32??QTqq\qq\chat.o
?????文件???????1341??2012-08-23?16:25??QTqq\qq\chat.ui
?????文件???????2265??2012-08-23?15:06??QTqq\qq\login.cpp
?????文件????????365??2012-08-23?10:15??QTqq\qq\login.h
?????文件?????359568??2012-08-23?16:31??QTqq\qq\login.o
?????文件???????1917??2012-08-23?16:28??QTqq\qq\login.ui
?????文件???????2530??2012-08-24?11:43??QTqq\qq\main.cpp
?????文件?????334868??2012-08-24?11:43??QTqq\qq\main.o
?????文件???????7457??2012-08-23?09:47??QTqq\qq\Makefile
?????文件???????2361??2012-08-23?15:59??QTqq\qq\moc_chat.cpp
?????文件?????302976??2012-08-23?15:59??QTqq\qq\moc_chat.o
?????文件???????2374??2012-08-23?10:16??QTqq\qq\moc_login.cpp
?????文件?????144928??2012-08-23?10:16??QTqq\qq\moc_login.o
?????文件?????754695??2012-08-24?11:43??QTqq\qq\qq
?????文件????????297??2012-08-23?09:44??QTqq\qq\qq.pro
?????文件??????10060??2012-08-24?11:52??QTqq\qq\qq.pro.user
?????文件???????7852??2012-08-23?16:43??QTqq\qq\se
?????文件???????3804??2012-08-23?15:28??QTqq\qq\se.c
?????文件???????2263??2012-08-23?16:32??QTqq\qq\ui_chat.h
?????文件???????2866??2012-08-23?16:30??QTqq\qq\ui_login.h
?????文件???????1554??2012-08-23?16:08??QTqq\qq1\qq\chat.cpp
?????文件????????723??2012-08-23?15:59??QTqq\qq1\qq\chat.h
?????文件?????315080??2012-08-23?16:43??QTqq\qq1\qq\chat.o
?????文件???????1341??2012-08-23?16:25??QTqq\qq1\qq\chat.ui
?????文件???????2265??2012-08-23?15:06??QTqq\qq1\qq\login.cpp
?????文件????????365??2012-08-23?10:15??QTqq\qq1\qq\login.h
?????文件?????359572??2012-08-23?16:43??QTqq\qq1\qq\login.o
?????文件???????1917??2012-08-23?16:28??QTqq\qq1\qq\login.ui
............此處省略21個文件信息
- 上一篇:GAMMA ISP使用文檔
- 下一篇:TE田納西-伊斯曼過程數據集
評論
共有 條評論