I've tried a lot of things, and yet I still can't figure this out. I saw this question was in the FAQ, I saw examples and I saw other peoples questions. The computers aren't even connecting, so I can't use wireshark. My goal was to create a simple chatroom before I did something a bit more complex. Here's my code:
#include <iostream>
#include <SFML/Network.hpp>
using namespace std;
using namespace sf;
int main() {
TcpSocket socket;
string txt = "Connected to ";
char message[2000];
cout << "Enter c for client and s for server: ";
char type, mode;
cin >> type;
if (type == 's') {
TcpListener listener;
listener.listen(2000);
listener.accept(socket);
txt += "Client!";
mode = 's';
} else if (type == 'c') {
socket.connect(IpAddress::LocalHost, 2000);
txt += "Server!";
mode = 'r';
}
socket.send(txt.c_str(), txt.size() + 1);
size_t received;
socket.receive(message, sizeof(message), received);
cout << txt << endl;
Packet packet;
packet << 5;
socket.send(packet);
socket.receive(packet);
bool done = false;
while (!done) {
if (mode == 's') {
getline(cin, txt);
socket.send(txt.c_str(), txt.length() + 1);
mode = 'r';
} else if (mode == 'r') {
socket.receive(message, sizeof(message), received);
if (received > 0) {
cout << message << endl;
mode = 's';
}
}
}
return 0;
}
What can I do to test this? Is my code just bad?