Jump to content
  • Advertisement
Sign in to follow this  
barakat

Telnet Chat Server

This topic is 4929 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
You have to keep track of all the client sockets, and use select() to figure out which ones of them have data to deliver.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!