Well I'm learning the irc protocol by coding a Console client.
The client appears to connect to server, set name and nick, But won't join the channel it just says "451 you have not registered".

Here's the code Sorry for any lame formatting ect. I'm kinda new to cpp:

#pragma comment(lib, "wsock32.lib ")
   #include <windows.h>
   #include <iostream>
   #include <stdio.h>
   #include <string.h>

      int main(){
      char buf1[1200];
	  char nick[] = "iarkeytest";
      char text1[4096];
	  char buf[4096];
	  int n;

      WSAData wsdata;
      WORD wsver=MAKEWORD(2, 0);
      int nret=WSAStartup(wsver, &wsdata);
      if(nret != 0){
      std::cout<<"Startup failed, error code: "<<WSAGetLastError();
      WSACleanup();
      return -1;
      }
       
      printf("Init success\n");
      SOCKET kSock=socket(AF_INET, SOCK_STREAM, 0);
      if(kSock == INVALID_SOCKET){
      printf("Socket init failed");
      return -1;
      }
       
      printf("Socket initialized\n");
      sockaddr_in sin;
      sin.sin_port=htons(6667);
      sin.sin_addr.s_addr=inet_addr("127.0.0.1");
      sin.sin_family=AF_INET;
      if(connect(kSock,(sockaddr*)&sin, sizeof(sin)) == SOCKET_ERROR){
      std::cout<<"Connect failed, error: "<<WSAGetLastError();
      WSACleanup();
      return -1;
      }
       
      printf("Connection successful!\n\n");
     
	  n = recv(kSock, buf1, sizeof(buf1)-1, 0);
      if ( n > 0 ) {
      buf1[n] = '\0';
      printf("%s\n",buf1);
      } else {
		  printf("No Data\n");
      }

      memset(text1,0,255);
      sprintf(text1, "NICK %s\r\nUSER %s 0 * :%s\r\n\0", nick, nick, nick);
      send(kSock, text1, strlen(text1), 0);
      printf(">>Client: %s\n",text1);

	   Sleep(100);

      memset(text1,0,255);
	  sprintf(text1,"JOIN #lobby\r\n");
      send(kSock, text1, sizeof(text1), 0);
      printf(">>Client: %s\n",text1);

      memset(text1,0,255);
      sprintf(text1,"PRIVMSG #lobby :Test Message\r\n");
      send(kSock,text1,sizeof(text1),0);
      printf(">>Client: %s\n",text1);


   while (1) {
   memset(buf,0,255);
   recv( kSock,buf,255,0);
	
   if ( strstr(buf,"PING") != 0 ) {
   printf("Server sent PING\n");
   send(kSock,"PONG :\r\n",6,0);
   printf("Replying with PONG\n");
   }
	
 memset(buf,0,255);
   }
}

c99 array varible lenght how this work?

plz answer me now!

commented: Wrong forum, off topic, and obnoxious... if I could give double -rep I would -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.