Newbie Spellweaver
- Joined
- Jun 1, 2014
- Messages
- 48
- Reaction score
- 2
Hey, i got a question^^
I rebuilded some of my old network Programms and i wanted to ask if someone could tell me if the Code is okey and what could i improove
This is the Client Handler callback:
I dont know if its okey or not, but i set the handler Public like this:
so that i can easy access it from another Class but i think this might be wrong(?)
I created a Little function to send easy my packets:
And i need to call it with the handler from my Program.cs is this okey or should i do it difrrent? im afraid that if i handle some more clients it wont work ^^
I rebuilded some of my old network Programms and i wanted to ask if someone could tell me if the Code is okey and what could i improove
This is the Client Handler callback:
Code:
private void HandleClient(IAsyncResult ar) {
StateObject state = (StateObject)ar.AsyncState;
[COLOR=#ff0000]handler = state.workSocket;[/COLOR]
if(!IsSocketConnected(handler))
{
handler.Close();
return;
}
int bytesRead = handler.EndReceive(ar);
if(bytesRead > 0)
{
/*Dispatch*/
byte[] inputMessage = new byte[bytesRead];
Array.Copy(state.buffer, inputMessage, bytesRead);
byte bOP = inputMessage[7];
Network.inputHandler.Dispatch(inputMessage,(Network.Enums.INPUT_OPCODE)bOP);
/*Dispatch*/
}
else
{
handler.Close();
}
}
Code:
public static Socket handler;
I created a Little function to send easy my packets:
Code:
public static void Send(Socket handler, byte[] data) {
handler.BeginSend(data, 0, data.Length, 0, new AsyncCallback(SendCallback), handler);
}
And i need to call it with the handler from my Program.cs is this okey or should i do it difrrent? im afraid that if i handle some more clients it wont work ^^