IRC client

I want write IRC client

But my connection to IRC server closed with message time OUT

I create tcp connection
void StartTCPClient ()
{
sprintf(client_cfg.nick,“newbie”);
sprintf(client_cfg.server,SRV1_ADDR);

socket = wip_TCPClientCreate(SRV1_ADDR, SRV1_PORT, TcpClientEVH, NULL);

firstRD=TRUE;
imm_log("TCP client START server: %s, socket= %d\r\n",client_cfg.server, socket);

}

and send strings to server

sprintf( Data,“NICK newbie\n\r”);
s32 r2=wip_write(socket, Data,Len);

Have you ever done such a thing before?

Have you studied the relevant RFCs :question:

hi

i write irc client

the irc server do not resolve my client host name … and afte it disconnect connection

how to resolve this problev ?

What is the socket after
socket = wip_TCPClientCreate(SRV1_ADDR, SRV1_PORT, TcpClientEVH, NULL);
? Is it a valid handle or an error code?

In my code (and it works) I start the bearer first (wip_bearerOpen, wip_bearerStart, wip_bearerSetOpts). I’m not sure if you can skip that.

Hi

wip_TCPClientCreate return valid handle

this messages returnn IRC server from irc.ircnet.ru

TCP client EVENT: READ
Read from socket 61 bytes
|:irc.rusirc.eu NOTICE AUTH :*** Looking up your hostname…
|TCP client EVENT: READ
Read from socket 90 bytes
|:irc.rusirc.eu NOTICE AUTH :*** Couldn’t resolve your hostname; using IP address instead

I send to IRC server commands
NICK_CMD
USER_CMD
JOIN_CMD

It seems you are receiving real messages from the IRC server, so the TCP connection is established correctly.

From that point on, we can’t really help you. You need to study the IRC protocol. There may be a timeout when you need to respond quickly, or the connection would close.

It would be a good move to set up a web server (or simply a TCP server) that prints incoming traffic, e.g. “TCP Client Server” from Nsasoft seems to do the job although I’ve never used it. It will help you to make sure that you are sending what you think you are sending.

milan_va
Thank you for answer

please check my irc client connection

void MakeTCPPacket(s16 cmd, char *Data, u32 Len)
{
	switch (cmd) {
		case START_CMD:

			sprintf( Data,"HELLO\n");
			break;



		case PING_CMD:

			sprintf( Data,"PING  %s\n", client_cfg.server);

			break;

		case PONG_CMD:

			sprintf( Data,"PONG  %s\n", client_cfg.server);

			break;


		case NICK_CMD:

			sprintf( Data,"NICK %s\n",client_cfg.nick );

			break;

		case JOIN_CMD:

			sprintf( Data,"JOIN #%s\n",client_cfg.channel );

			break;

		case USER_CMD:

			sprintf( Data,"USER %s * * :cbvm02\n",client_cfg.nick );

			break;


		default:
			sprintf(Data,"PING %s\n",client_cfg.server);
			break;

		Len=strlen(Data)-1;


	}

}

////***********************


void IRCLogin()
{
	u32 Len=0;
	 u32 st1=wip_getState(socket);
	 imm_log(" wip state =%d \r\n",st1);
 s32 r0= wip_write(socket, TCPSendBuf,Len);
		 // imm_log("wip write \r\n");
		  imm_log("wip write ret=%d, %s\r\n",r0,TCPSendBuf);

		  MakeTCPPacket( NICK_CMD , TCPSendBuf,Len);

		  s32 r1=wip_write(socket, TCPSendBuf,Len);
		  imm_log("wip write ret=%d, %s\r\n",r1,TCPSendBuf);

		MakeTCPPacket( USER_CMD , TCPSendBuf,Len);

		 s32 r2=wip_write(socket, TCPSendBuf,Len);
		 imm_log("wip write ret=%d, %s\r\n",r2,TCPSendBuf);

		 MakeTCPPacket( JOIN_CMD , TCPSendBuf,Len);

		 s32 r3=wip_write(socket, TCPSendBuf,Len);
		 imm_log("wip write ret=%d, %s\r\n",r3,TCPSendBuf);



}

////  TCP client control handler


 void TcpClientEVH( wip_event_t *ev, void *ctx)
  {
  	 u8 buffer[1520];
  	 s32 nread;
	u32 Len=0;
	// imm_log("TCP client EVENT = %d\r\n");


	 switch (ev->kind) {
		case WIP_CEV_OPEN:

			  imm_log("TCP client EVENT: OPEN\r\n");

			   //IRCLogin();

			 // Ping_tmr=adl_tmrSubscribe ( TRUE, 100, ADL_TMR_TYPE_100MS, PING_TimerHandler );
			break;

		case WIP_CEV_READ:
 			imm_log("TCP client EVENT: READ\r\n");

			nread = wip_read( socket, buffer, sizeof( buffer) - 1);
			buffer[nread] = '\0';

			if (nread>1500) 	buffer[1500] = 0;

			imm_log(" Read from socket %d bytes\r\n |%s|",nread, buffer );



			break;

		case WIP_CEV_WRITE:
		 	imm_log("TCP client EVENT: WRITE\r\n");


		 	if (!connected)
		 	{
		 		//Login_tmr=adl_tmrSubscribe ( TRUE, 30, ADL_TMR_TYPE_100MS, Login_TimerHandler );
		 		IRCLogin();
		 		connected=true;
		 	}


			break;

		case  WIP_CEV_DONE:
		 	imm_log("TCP client EVENT: DONE\r\n");

			break;

		case  WIP_CEV_ERROR:
		 	imm_log("TCP client EVENT: ERROR\r\n");

			break;

		case  WIP_CEV_PEER_CLOSE:
		 	imm_log("TCP client EVENT: CLOSE BY PEER\r\n");

		 	wip_close(socket);
		 	//adl_tmrUnSubscribe(Ping_tmr,PING_TimerHandler,ADL_TMR_TYPE_100MS);
		 	//adl_tmrUnSubscribe(Ping_tmr,);
			break;

		case  WIP_CEV_PING:
		 	imm_log("TCP client EVENT: PING\r\n");

			break;


		default:
			break;
	}


 }

Best regards

It seems reasonable, although there are a few things.

  • I think the -1 in MakeTCPPacket line Len=strlen(Data)-1; is wrong.

  • In IRCLogin(), you need to be ready for a situation where the wip_write() function returns with an error because the output buffer is full. Your messages are small so they might all fit in the default buffers, but eventually you’ll have to abandon this simple approach.

  • What are the outputs of imm_log functions? You should be able to figure out your problem from these results.

    Milan

That’s a good idea, I’ll keep track of your steps