Sign in to follow this  
barakat

Telnet Chat Server

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this