Hi,
I've made a little chatprogramm(just for fun
) and I have this little problem you can see in the title.
the full error message is
"Unhandled exception at 0x773f15de in sfmlserver.exe: 0xC0000005: Access violation."
It pops up everytime my client is connecting to my server (both on my computer).
Actually I don't even know if the connection causes the problem.
code of the server:
#include<SFML\Audio.hpp>
#include<SFML\Graphics.hpp>
#include<SFML\Network.hpp>
#include<iostream>
#include<string>
#include<vector>
#include<conio.h>
int main()
{
std::cout<<"server is online"<<std::endl;
sf::TcpListener list;
sf::SocketSelector select;
std::vector<sf::TcpSocket*> clients;
list.listen(50000);
select.add(list);
while(true){
if(select.wait()){
if(select.isReady(list)){
sf::TcpSocket *socket = new sf::TcpSocket;
list.accept(*socket);
sf::Packet packet;
std::string id;
if(socket->receive(packet)==sf::Socket::Done)
packet>>id;
std::cout<< id << " has joined the chatroom" << std::endl;
clients.push_back(socket);
select.add(*socket);
}
else{
for(int i=0;i<clients.size();i++){
if(select.isReady(*clients[i])){
sf::Packet pack;
if(clients[i]->receive(pack)==sf::Socket::Done){
std::string text;
for(int j=0;i<clients.size();j++){
if(j!=i){
clients[j]->send(pack);
}
}
}
}
}
}
}
for(std::vector<sf::TcpSocket*>::iterator it=clients.begin(); it!=clients.end();it++)
delete *it;
}
system("pause");
return 0;
}