What don't you understand? It's really trivial, and not more complicated than with TCP sockets. There are examples in the documentation, tutorials and example applications.
Then what do I need to change in this code?
pre-window:
sf::TcpSocket socket;
char connectionType;
cout << "Enter ip you wish to host/connect to." << endl;
string tmp;
cin >> tmp;
sf::IpAddress ip(tmp);
cout << "Port: ";
int port;
cin >> port;
cout << "(s) for server and (c) for client: ";
cin >> connectionType;
if (connectionType == 's') {
cout << "Waiting for someone to join..." << endl;
sf::TcpListener listener;
listener.listen(port);
listener.accept(socket);
}
else {
cout << "connecting..." << endl;
socket.connect(ip, port);
}
........
game loop:
sf::Packet packet;
if (prevPosition != rect1.getPosition() | prevRot != rot) {
packet << rect1.getPosition().x << rect1.getPosition().y << rot;
socket.send(packet);
}
socket.receive(packet);
if (packet >> p2Position.x >> p2Position.y >> rot2) {
rect2.setPosition(p2Position);
}