日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

c语言中void msg,如何连接到IRC服务器/解析C语言(提供代码)的IRC MSG/PING-PONG处理...

發(fā)布時(shí)間:2024/4/14 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言中void msg,如何连接到IRC服务器/解析C语言(提供代码)的IRC MSG/PING-PONG处理... 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

正在用C語(yǔ)言編寫(xiě)IRC客戶(hù)端。并在連接到serwer時(shí)遇到了一些問(wèn)題。 我碰到下面當(dāng)我運(yùn)行程序:如何連接到IRC服務(wù)器/解析C語(yǔ)言(提供代碼)的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:: - 表示由程序傳遞給現(xiàn)在,所以我不必輸入很多次。

btw。我連接到irc.gbatemp.net:5190(無(wú)需密碼,只要我擔(dān)心)

在提供必要的數(shù)據(jù)10-20秒后發(fā)生中斷(我在OUTPUT部分中指定)并且ERROR temp.net部分如下廣告infinitum(我用點(diǎn)劃線)

所以問(wèn)題的主要部分是我應(yīng)該如何以及何時(shí)發(fā)送PONG消息來(lái)響應(yīng)PING?我做了我的研究,但仍然無(wú)法做到。為什么不能在STDOUT中看到PING消息? (1)循環(huán)還不完美,但我認(rèn)為它是s(012)(012)(012)(012)代碼為另一個(gè)主題)代碼波紋管:

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;

}

}

//--------------------------------------------------------------------------

好的。我將在未來(lái)為其他人留下問(wèn)題并提供答案。這是瑣事。

我剛剛在USER變量的末尾添加了\ n \ r(就像在NICK字符串中一樣)。 連接就像一個(gè)魅力!

在最后:))

2012-05-07

azrahel

總結(jié)

以上是生活随笔為你收集整理的c语言中void msg,如何连接到IRC服务器/解析C语言(提供代码)的IRC MSG/PING-PONG处理...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。