Hello everyone, I have been working on a project and I am adding some networking now. My small scale tests worked by sending a byte to trigger a specific if statement and 2 strings for user name and password. I have recently added a new one to get the the network ID from the net message from and then send it back to the client. Now the username and password byte is 105 and sometimes 115. I was using NetSend(0) and I have tried NetSend(1) then 0. I do not know where I am going wrong with sending network messages because the first username and password sent correctly.
A change in my code is getting the network ID
//SEND A REQUEST '0' FOR NETWORK ID AND STORE IT INTO ME.
if (me==0)
{
me = -1;
NetPutByte(0);
NetSend(1);
NetSend(0);
}//END SEND REQUEST 0
This is the code I am having problems with, I send to the network and I get 115 as the byte or 105 sometimes.
//SEND NETWORK INFORMATION
NetPutByte(1); //SEND A LOGIN REQUEST TO THE SERVER
NetPutString(accountname); //SEND THE ACCOUNT NAME TO THE SERVER
NetPutString(accountpassword); //SEND THE PASSWORD TO THE SERVER
NetSend(1);
NetSend(0);
mygui.seterror("Attempting Connection!"); //let the user know its sending
This is the code in the client so far that receives messages from the main loop, if it gets a net message it sends it to this, but I cant get the server to accept the login message so there is nothing to send back.
void handlenet(int type){
//HANDLE ID REQUEST
if (type == 0){
me=NetGetInt();
}//end id request
}//end handle net message
Other than while loops, this is all of the networking my program does. It seems simple to send a net message and I think it is. I just dont know what I am doing wrong with it. I hope someone can help me out. I can post more code if needed, but this is the networking stuff. Below is the server and everything above is the client. Also, the first part to get network id seems to work correctly.
if (NetGetMessage())
{
int fromplayer = NetMessageFrom();
dbText(0, 200, "There is a message");
if (NetGetByte()==0)
{
NetPutByte(0);
NetPutInt(fromplayer);
NetSend(fromplayer);
dbCLS();
dbText(0, 90, "Sent the player number");
}
else if (NetGetByte()==1)
{ char username[1000];
char password[1000];
char * message;
message = dbStr(fromplayer);
NetGetString(username, 100);
NetGetString(password, 100);
strcat(message, username);
strcat(message, password);
dbCLS();
dbText(0, 0, message);
}
else {
dbCLS();
dbText(0, 0, dbStr(NetGetByte()));
dbText(0, 30, "The above byte is not a menu option!!!");
}
}//end get message
mfield