1 Replies - 2743 Views - Last Post: 17 November 2012 - 01:13 PM Rate Topic: -----

#1 Nano511  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 145
  • Joined: 07-October 12

SFML chat program using boost for multithreading

Posted 17 November 2012 - 10:39 AM

The program runs fine. I type in the ip adress i want to connect to and connect to the server fine, but after about 5 seconds i get this break-continue box message
unhandled exception at ...:
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<
boost::thread_resource_error> > at memory location 0x003ff964..




Here is the relevant client code:
//in main()
while( Connected )
	{
		//Thread for sending messages
		tgroup.create_thread( boost::bind(&SendMessage) );
		
		//Thread for receiving messages
		tgroup.create_thread( boost::bind(&ReceiveMessage) );
	}

	// Close the socket
	socket.disconnect();

	//main thread waits for all threads to join back together
	tgroup.join_all();

	return 0;
}

//Thread functions
void SendMessage()
{
	// Let the user write a message
	std::string SendMessage;
	std::getline(std::cin, SendMessage);

	// Send it to the server
	sf::Packet SendPacket;
	SendPacket << SendMessage;
	std::cout<<"Sending message : "<<SendMessage<<std::endl;
	if(socket.send(SendPacket) != sf::Socket::Done)
		std::cout<<"Error sending message"<<std::endl;
}

void ReceiveMessage()
{
	// Receive from the server
	sf::Packet ReceivePacket;
	std::string ReceiveMessage;
	if(socket.receive(ReceivePacket) == sf::Socket::Done)
	{
		ReceivePacket >> ReceiveMessage;
		std::cout << "Received Message : "<<ReceiveMessage << std::endl;
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: SFML chat program using boost for multithreading

#2 Nano511  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 145
  • Joined: 07-October 12

Re: SFML chat program using boost for multithreading

Posted 17 November 2012 - 01:13 PM

Connected is always true, btw It was old code that i just kept, but Connected is declared true right before the while loop starts.

Anyways, i added a start and end message to the beginning and end of both thread functions, and found something interesting.

This is the output:
SendMessage StartReceiveMessage Start
ReceiveMessage Start
SendMessage Start
SendMessage Start
ReceiveMessage Start
// etc



The interesting thing is that "SendMessage End" nor "ReceiveMessage End" were ever outputted. It seems like the threads just keep restarting. Im really new to threads so I'm going to need some help explaining this behavior.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1