16
General / Here are compiled SFML 2.0 lib for Visual Studio 2010
« on: September 28, 2010, 06:59:48 pm »
Look at the Date of the Post....Name change was ~1 Month ago, the post is from July....
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
class myClass {
sf::RenderWindow &app;
myClass(sf::RenderWindow &app);
}
myClass::myClass ( sf::RenderWindow &app) : app(app) {
<foo>
}
int main() {
sf::RenderWindow App(...);
myClass foo(App);
}
By the way, if you'd given me a true minimal code (ie. with no cClient class), you'd have found the error by yourself...
When people here ask for minimal codes, they are not asking for pieces of your original code, but instead they want the poster to find the actual piece of code which is really causing the problem; the solution often comes naturally after doing that.
#include "server.hpp"
cClient::cClient(sf::TcpSocket *socket, sf::Uint32 UID) {
this->socket = socket;
this->UID = UID;
}
cClient::~cClient() {
this->socket->Disconnect();
delete this->socket;
}
sf::Uint32 cClient::getUID() {
return this->UID;
}
int main() {
unsigned short Port = 1337;
sf::SocketSelector selector;
sf::TcpListener listener;
//std::list<sf::TcpSocket*> clients;
std::list<cClient> clientList;
listener.Listen(Port);
selector.Add(listener);
sf::Uint32 UID;
std::cout << "Server is listening to Port " << Port << ", waiting for connections..." << std::endl;
while (true) {
if (selector.Wait()) {
std::cout << "#" << std::endl;
if (selector.IsReady(listener)) {
std::cout << "b" << std::endl;
UID++;
sf::TcpSocket* client = new sf::TcpSocket;
if (listener.Accept(*client) == sf::Socket::Done) {
cClient newClient(client, UID);
// clients.push_back(client);
clientList.push_back(newClient);
selector.Add(*client);
std::cout << "New Client connected!" << std::endl;
}
} else {
std::cout << "or what?" << std::endl;
for ( tClientList::iterator it = clientList.begin(); it != clientList.end(); ++it ) {
sf::TcpSocket& client = *it->socket;
if ( selector.IsReady(client) ) {
sf::Packet packet;
if (client.Receive(packet) == sf::Socket::Done) {
std::string Message;
packet >> Message;
if ( Message == "qq" ) {
selector.Remove(client);
client.Disconnect();
std::cout << "Socket closed." << std::endl;
} else {
std::cout << "A client says : \"" << Message << "\"" << std::endl;
}
} else {
std::cout << "Socket Killed" << std::endl;
selector.Remove(client);
}
}
}
}
}
}
}
sf::View tmpView = app.GetView();
sf::FloatRect tmpRect;
sf::VideoMode vMode;
vMode = vMode.GetDesktopMode();
sf::Uint32 posL = (vMode.Width/2) - (width/2);
sf::Uint32 posT = (vMode.Height/2) - (height/2);
tmpRect.Top = 0;
tmpRect.Bottom = height;
tmpRect.Left = 0;
tmpRect.Right = width;
tmpView.SetFromRect(tmpRect);
app.SetView(tmpView);
app.SetSize(width, height);
app.SetPosition(posL, posT);
app.Clear(sf::Color(255,255,255));
app.Display();