Hi (sorry for my bad english)
I am currently trying to implement a function to send and receive maps and tilemap, but the problem is when sending the file gets corrupt for lack of approximately 2000 bytes.
I've tried sending other files without success.
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <string>
#include <fstream>
int main(){
char resp;
std::cin >> resp;
sf::TcpSocket socket;
std::cout << "s = Server c= Client" << std::endl;
if(resp=='s')
{
sf::TcpListener escucha;
escucha.listen(43000);
char Buffer[4096];
if (escucha.accept(socket) == sf::Socket::Done)
{
std::ifstream File("send.bmp", std::ifstream::binary | std::ios::in | std::ios::binary);
while (File.read(Buffer, sizeof(Buffer)))
{
socket.send(&Buffer, sizeof(Buffer));
//std::cout << Buffer << std::endl;
//sf::sleep(sf::milliseconds(30));
}
std::cout << "Done" << std::endl;
}
}
else if(resp=='c')
{
std::cout << "Connecting" << std::endl;
std::ofstream outfile("receive.bmp",std::ofstream::binary);
if (socket.connect("127.0.0.1", 43000, sf::seconds(10)) != sf::Socket::Done)
{
std::cout << "Conection failed" << std::endl;
}
else std::cout << "Connected" << std::endl;
socket.setBlocking(false);
while(1){
char Buffer[4096];
std::size_t Size = 0;
socket.receive(&Buffer, sizeof(Buffer),Size);
outfile.write(Buffer, Size);
//std::cout << Buffer << std::endl;
}
}
system("PAUSE");
return 0;
}
What is wrong ?
Thanks for you help!