c语言中void msg,如何连接到IRC服务器/解析C语言(提供代码)的IRC MSG/PING-PONG处理...
正在用C语言编写IRC客户端。并在连接到serwer时遇到了一些问题。 我碰到下面当我运行程序:如何连接到IRC服务器/解析C语言(提供代码)的IRC MSG/PING-PONG处理
输出
Set Fully Qualified host Domain Name(human readable): ::automaticaly provided::
Set the port number of the server You want to connect to: ::automaticaly provided::
Destination server IP: 88.190.23.245
Socket descriptor: 3
Connection has been successfully established
Peer's IP is: 88.190.23.245
Peer's port is: 5190
:irc2.gbatemp.net NOTICE AUTH :*** Looking up your hostname...
:irc2.gbatemp.net NOTICE AUTH :*** Found your hostname (cached)
Type Your nick name: ::automaticaly provided::
Type Your user name: ::automaticaly provided::
(10-20 seconds break here and than what follows down here)
ERROR :Closing Link: thisIsMyNickNameXXXa[85.221.165.54] (Ping timeout)
temp.net NOTICE AUTH :*** Found your hostname (cached)
ERROR :Closing Link: thisIsMyNickNameXXXa[85.221.165.54] (Ping timeout)
temp.net NOTICE AUTH :*** Found your hostname (cached)
ERROR :Closing Link: thisIsMyNickNameXXXa[85.221.165.54] (Ping timeout)
temp.net NOTICE AUTH :*** Found your hostname (cached)
.......
.............
...................
========================= ====================================
::automaticaly provided:: - 表示由程序传递给现在,所以我不必输入很多次。
btw。我连接到irc.gbatemp.net:5190(无需密码,只要我担心)
在提供必要的数据10-20秒后发生中断(我在OUTPUT部分中指定)并且ERROR temp.net部分如下广告infinitum(我用点划线)
所以问题的主要部分是我应该如何以及何时发送PONG消息来响应PING?我做了我的研究,但仍然无法做到。为什么不能在STDOUT中看到PING消息? (1)循环还不完美,但我认为它是s(012)(012)(012)(012)代码为另一个主题)代码波纹管:
int readReady=0;
int writeReady=0;
pid_t pID;
char buf[1024]; //I/O buffer (?)
pid_t sID;
char *NICK = "NICK thisIsMyNickNameXXXa\n\r";
char *USER = "USER tomaazrxtc 8 * :nameandsurname";
char ping[512];
char *change;
pID=fork();
if(pID < 0){
//failed to execute fork()
perror("Error while forking");
getchar();getchar();
exit(1);
}
if(pID > 0){
exit(0);
}
//child down here
//setting new session
sID = setsid();
if(sID < 0){
perror("Error while setting new session");
getchar();getchar();
exit(1);
}
//---------receiving NOTICE AUTH :*** part-------------------------------
if(recv(sockfd, buf, 1024,0)>0){
printf(buf);
}
else{
perror("Error while receiving data");
}
//---------providing and sending NICK and USERNAME-----------------------
printf("Type Your nick name: \n");
//scanf(nickname); pamietaj zeby zapewnic podawanie tylko nicku, a format handler zrobic osobno
send(sockfd, NICK, strlen(NICK), 0);
printf("Type Your user name: \n");
//scanf(username); pamietaj zeby zapewnic podawanie tylko nicku, a format handler zrobic osobno
send(sockfd, USER, strlen(USER), 0);
//--------Shoudnt I receive PING message just here ?????-----------------
recv(sockfd, buf, strlen(buf), 0);
printf(buf);
//--------PONG'ing function which I havent tested yet since i cant see PING message----
recv(sockfd, ping, 512,0);
if(strstr(ping, "PING")){
change = strstr(ping, "PING");
strncpy(change, "PONG", 4);
send(sockfd, ping, 512, 0);
}
//-------------------------------------------------------------------------
while(1){
//sleep(1);
if((readReady = readReadiness(sockfd))==0){ //nothing to recv
if((writeReady = writeReadiness(sockfd))>0){ //sending is possible
scanf(buf);
send(sockfd, buf, strlen(buf), 0);
continue;
}
else
continue; //if there s no data to read and cant send (is it even possible?)
}
else{ //if there s some data to recv() on the socket buffer
recv(sockfd, buf, strlen(buf), 0);
printf(buf);
continue;
}
}
//--------------------------------------------------------------------------
好的。我将在未来为其他人留下问题并提供答案。这是琐事。
我刚刚在USER变量的末尾添加了\ n \ r(就像在NICK字符串中一样)。 连接就像一个魅力!
在最后:))
2012-05-07
azrahel
c语言中void msg,如何连接到IRC服务器/解析C语言(提供代码)的IRC MSG/PING-PONG处理...相关推荐
- c语言中void delay0.5(),第5章补充 单片机C语言基础.ppt
第5章补充 单片机C语言基础.ppt 2.中断函数举例 例4-16 本例程序电路图可参考图4-1.下面的程序的功能是:对外部中断1中断次数计数,并送P0口显示. #include unsigned c ...
- c语言中void指针,C 语言 void指针
C 语言 void指针 到目前为止,我们已经研究了分配给指针的地址应该与指针声明中指定的类型相同. 例如,如果我们声明了int指针,则此int指针不能指向float变量或某种其他类型的变量,即它只能指 ...
- c语言void结尾,C语言中void*详解及应用
void在英文中作为名词的解释为"空虚:空间:空隙":而在C语言中,void被翻译为"无类型",相应的void *为"无类型指针".void ...
- c语言中void和void*类型
1.void的作用 c语言中,void为"不确定类型",不可以用void来声明变量.如:void a = 10:如果出现这样语句编译器会报错:variable or field ' ...
- c语言里void什么作用,C语言中void是什么意思?
C语言中void是什么意思? C语言中"void"表示为无类型,相应的"void *"为无类型指针,常用在程序编写中对定义函数的参数类型.返回值.函数中指针类型 ...
- c语言中void函数,c语言中void的用法
c语言中void的用法的用法你知道吗?下面小编就跟你们详细介绍下c语言中void的用法的用法,希望对你们有用. c语言中void的用法的用法如下: void指针是什么? void指针一般被称为通用指针 ...
- c语言里void什么作用,c语言中void的含义是什么?如何使用?
c语言中void的含义是什么?如何使用? 发布时间:2020-04-26 14:08:27 来源:亿速云 阅读:416 作者:小新 c语言中void的含义是什么?如何使用?相信有很多人都不太了解,今天 ...
- C 语言中 void* 详解及应用介绍
void 在英文中作为名词的解释为 "空虚.空间.空隙",而在 C 语言中,void 被翻译为"无类型",相应的void * 为"无类型指针" ...
- C语言中 void* 详解及应用
void在英文中作为名词的解释为"空虚:空间:空隙":而在C语言中,void被翻译为"无类型",相应的void *为"无类型指针".void ...
最新文章
- 如何使double为整数时不带小数点
- 一文带你了解 MySQL 中的各种锁机制!
- LINUX系统管理员技术(Admin)-------第三天
- vs社区版到期离线激活_vs2019离线安装包
- Java 常见异常种类
- mysql binlog2sql闪回数据
- Bug : Bash on Ubuntu on Windows scp work on window but not in shell file
- 一罐将其全部统治:Arquillian + Java 8
- win7文件和文件夹可以重名吗_Win7下如何重命名,替换System32文件夹下的系统文件...
- SLAM_ORB-SLAM3回环检测是怎么做的?
- Asp.net MVC的ViewData与ViewBag以及TemplateData的使用与区别
- 西南大学计算机应用基础作业答案2020,2018秋【西南大学】[0483]《计算机应用基础》作业(资料)...
- 我的管理成长与思考 - 那些领导的真相,理解和思考
- 正余弦变换、和差、倍角公式
- windows开启nfs_win7专业版怎么开启nfs_win7专业版启用nfs步骤
- gitter 卸载_最佳Gitter渠道:Node.js
- go实现 LeetCode 1227 飞机座位分配概率
- 绘制奥林匹克五环旗。
- 俞敏洪一分钟励志演讲稿
- 打印一年内任意月份的日历(C语言)
热门文章
- 使用vuex实现父组件调用子组件方法
- 数学建模 TSP(旅行商问题) Lingo求解
- HTML5本地存储 localStorage
- Modbus和RS485是什么关系
- 【转】Eclipse Code Recommenders正式发布 智能代码建议工具
- Java编程初学者应该了解的编程框架
- ADS_LPC2103开发板SPI 4位数码管测试试验
- HTML5纯Web前端也能开发直播,不用开发服务器(使用face2face)
- Leetcode-998 Maximum Binary Tree II(最大二叉树 II)
- 测试Open Live Writer