Network several connections TCP server

Hello guys!

When i connect with my client it works great and in the console for the server it pop up that I have joined. When I then try to join the server from my other computer nothing happens, and in the console for the server nothing pops up that I have joined.
I have also try to first join with my other computer first and it works great but then when I try to join with my other computer nothing happens.
The server seems just only can take one TCP Connection.
I need some help to solve this problem!

Thanks.

the code in my server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
int main()
{
	std::cout << "Server Running" << std::endl;

	//se om server får några connections från någon client, bara om dom pekar man kan säga att listener håller i connectins
	sf::TcpListener listener;

	//tar imot connections, så flera kan ta imot connections
	sf::SocketSelector selector;

	bool done = false;
	
	
	std::string connected;
	std::string id;
	
	//clienterna som ansluter sig till servern
	std::vector<sf::TcpSocket*> clients;
	int Connected;
	unsigned short port;
	std::cout << "Type the portnumber:";
	std::cin >> port;
	
	//listenern hör till denna port alltså ervern
	listener.listen(port);


	selector.add(listener);


	while (!done)
	{
		if (selector.wait(sf::Time::Zero))
		{
			if (selector.isReady(listener))
			{
				sf::TcpSocket *client = new sf::TcpSocket;
				if (listener.accept(*client) == sf::Socket::Done)
				{
					clients.push_back(client);
					selector.add(*client);
				}
				
				
			}
			else
			{
				for (std::vector<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end();)
				{
					sf::TcpSocket &client = **it;
					if (selector.isReady(client))
					{
						// The client has sent some data, we can receive it
						sf::Packet packet;
						if (client.receive(packet) == sf::Socket::Done)
						{
							
							PacketTypeBool type;
							packet >> type >> id;
							if (type == SendStringID)
							{
								std::cout << id << " has connected" << std::endl;

							}
							std::cout << clients.size() << std::endl;
						}

						if (client.receive(packet) == sf::Socket::Disconnected)
						{
							std::cout << id << " disconnected" << std::endl;
							std::cout << "list size: " << clients.size();
							selector.remove(client);
							client.disconnect();
							delete(&client);
							it = clients.erase(it);


							std::cout << " then: " << clients.size() << std::endl;
						}
						else
						{
							++it;
						}

					}
				}
			}
		}
	}

	system("Pause");
	return 0;
}


Last edited on
You should try posting to the SFML forums. http://en.sfml-dev.org/forums/index.php?board=9.0
Topic archived. No new replies allowed.