• Advertisement
Sign in to follow this  

Telnet Chat Server

This topic is 4603 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am trying to make a simple telnet chat server ... i .. socket() .. bind() .. listen() .. the accept() here goes the problem i want every one to send in turn ... :S cant figure it out ... everything is mixed and i get stupid outputs i did that ...

while(1){
		
		sockaddr_in clientaddr;
		int addrlen = sizeof(sockaddr_in);
		if((clientsock = accept(mainsock , (sockaddr*)&clientaddr , &addrlen))!= SOCKET_ERROR){
			char buffer[1000] = { 0 };
			send(clientsock ,welcomeMessage , strlen(welcomeMessage) ,0);
			cout<<"got connection from "<<inet_ntoa(clientaddr.sin_addr)<<endl;
			int recieved = recv(clientsock , buffer , 80 ,0);
			while(recieved>0){
				char dataToSend[1000] = { 0 };
				//strcat(buffer,"\r\n");
				logInfo(buffer);
				strcpy(buffer,"");				
				cout<<"\t\t: ";cin>>dataToSend;
				strcat(dataToSend,"\r\n");
				
				send(clientsock,dataToSend , strlen(dataToSend),0);
				recieved = recv(clientsock , buffer , 80 ,0);
			}

		}
		closesocket(clientsock);
	}


Thanks in Advance

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement