IRCクライアントにIRCクライアントを記述しています。 serwerに接続中にいくつかの問題が発生しました。 私はプログラムを実行すると、私は、次を得る:C言語でIRC MSG/PING-PONGの処理(コード提供)
OUTPUT
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部分に指定されています)。広告無限(私はドットでマークしました)
したがって、問題の主な部分は、いつどのようにPINGに応答してPONGメッセージを送信すべきですか?私は研究をしましたが、それでもそれはできません。なぜ私はSTDOUTにPINGメッセージが表示されないのですか?
出力とPINGPONGの部分のコードは、 です(現在の主な問題は、PING TIMEOUTとPING PONGはPING TIMEOUTと書かれています)。(1)ループは完全ではありませんが、別のトピックの対象)
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;
}
}
//--------------------------------------------------------------------------
[OK]をクリックします。私は将来他人のための質問を残し、答えを提供します。それはtrivalだった。
私はUSER変数の末尾に\ n \ rを追加しました(ちょうどNICK文字列のように)。 チャームのように接続!最後に
:))