Sign in to follow this  
levijgraham

i really need some help

Recommended Posts

i have attached a picture of the error i get it when i send my map between the server and the client.
theres my main
[code]#include <iostream>
#include <string>
#include "GameState.h"
#include "Socket.h"
#include "Level.h"

using namespace std;

GameState CurrentGameState;
const int STRLEN = 256;
const int MAPLENGTH = 250;
Level CurrentLevel;

int main()
{
CurrentLevel.init();
int port = 666;
char *ipAddress = "127.0.0.1";
char recMessage[STRLEN];
char sendMessage[STRLEN];
bool run = true;
while (true)
{
int a = CurrentGameState.run();
if(a == 1)
{
bool run2 = true;
ServerSocket sockServer;
cout << "HOSTING..."<<endl;
sockServer.StartHosting(port);
sockServer.Listen();
while (run2)
{
char sendMap[MAPLENGTH];
CurrentLevel.draw();
CurrentLevel.Edit(true);
int id = 0;
for(int y = 0;y < 10;y++)
{
for(int x = 0;x < 25;x++)
{
sendMap[id] = CurrentLevel.map[x][y];
id++;
}
}
sockServer.SendData( sendMap );

sockServer.ReceiveData(sendMap,MAPLENGTH);
id = 0;
for(int y = 0;y < 10;y++)
{
for(int x = 0;x < 25;x++)
{
CurrentLevel.map[x][y] = sendMap[id];
id++;
}
}

if (strcmp(recMessage,"end") == 0 || strcmp(sendMessage,"end") == 0)
{
run2 = false;
}
}
}
else if(a == 2)
{
ClientSocket sockClient;
cout << "ATTEMPTING TO CONNECT" << endl;
sockClient.ConnectToServer(ipAddress,port);
bool run2 = true;
while (run2)
{
char sendMap[MAPLENGTH];
CurrentLevel.draw();
sockClient.ReceiveData(sendMap,MAPLENGTH);
int id = 0;
for(int y = 0;y < 10;y++)
{
for(int x = 0;x < 25;x++)
{
CurrentLevel.map[x][y] = sendMap[id];
id++;
}
}
CurrentLevel.Edit(false);

id = 0;
for(int y = 0;y < 10;y++)
{
for(int x = 0;x < 25;x++)
{
sendMap[id] = CurrentLevel.map[x][y];
id++;
}
}
sockClient.SendData( sendMap );

if (strcmp(recMessage,"end") == 0 || strcmp(sendMessage,"end") == 0)
{
run2 = false;
}
}
sockClient.CloseConnection();
}
else if(a == 3)
{
exit(0);
}
}
return 0;}[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this