• Create Account

### #ActualTheis_Bane

Posted 24 February 2013 - 07:05 PM

Whatever you've seen "floating around the interwebs" ... is not likely to be a reputable source, so proceed with caution there.

Herein lies most of my problems.  NOTHING I've found ANYWHERE on the webs looks anything like what I'm working on right now.  It's like there's some massive conspiracy to prevent new programmers from fully grasping how socket programming works.  I'm worried for you, Kylotan.  The Socket Police are reading this thread.  They know what you've done.  And they are NOT happy.

Okay...so I spent about half an hour staring at your post, trying to get my head around it, trying to work past all the bad or incomplete information I already had...and here's what I've come up with.  It SEEMS to follow everything you've said, but I'm sure you'll see something I don't.  I think, by the time I'm done, I'll have myself an Enterprise-level network protocol at my disposal lol.

private void ReceiveMessage(IAsyncResult Result)
{
ClientInfo thisClient = (ClientInfo)Result.AsyncState;

//If we've received any sort of message...
{
}
}

private void GetMessage(ClientInfo Client, int DataLength)
{
//Translate the message
string Contents = Encoding.UTF8.GetString(Client.Buffer, 0, DataLength);

int TermLoc = 0;

while (true)
{
TermLoc = Contents.IndexOf(FOOTER);

if (TermLoc == -1 & Contents.Length == 0)
{
return;
}
else if (TermLoc == -1 & Contents.Length > 0)
{
int StartIndex = DataLength - Contents.Length;

Array.Copy(Client.Buffer, StartIndex, Client.Buffer, 0,  Contents.Length);
Client.WorkSocket.BeginReceive(Client.Buffer, StartIndex, BUFFER_SIZE - StartIndex, SocketFlags.None,
return;
}

//Parse message and send it to game loop
PassMessage(Client, Contents.Substring(0, TermLoc));

//Removed received message and look for more
Contents = Contents.Substring(TermLoc + 2, Contents.Length - (TermLoc + 2));
}
}

private void PassMessage(ClientInfo Client, string Message)
{
string[] Split = Message.Split('');
string[] AccountSplit = Split[0].Split('~');
string[] MessageSplit = Split[1].Split('~');

//Message received format = AccountID~CharacterIDect~ect.
RequestModel Request = new RequestModel();
Request.Client = Client.WorkSocket;
Request.AccountName = AccountSplit[0];
Request.CharacterID = AccountSplit[1];
Request.Request = MessageSplit;
}


EDIT - I just wanted to reiterate how grateful I am that you are taking time out of your day to help me out with this.  You've been both patient and eloquent, and I thank you.

### #2Theis_Bane

Posted 24 February 2013 - 06:55 PM

Whatever you've seen "floating around the interwebs" ... is not likely to be a reputable source, so proceed with caution there.

Herein lies most of my problems.  NOTHING I've found ANYWHERE on the webs looks anything like what I'm working on right now.  It's like there's some massive conspiracy to prevent new programmers from fully grasping how socket programming works.  I'm worried for you, Kylotan.  The Socket Police are reading this thread.  They know what you've done.  And they are NOT happy.

Okay...so I spent about half an hour staring at your post, trying to get my head around it, trying to work past all the bad or incomplete information I already had...and here's what I've come up with.  It SEEMS to follow everything you've said, but I'm sure you'll see something I don't.  I think, by the time I'm done, I'll have myself an Enterprise-level network protocol at my disposal lol.

private void ReceiveMessage(IAsyncResult Result)
{
ClientInfo thisClient = (ClientInfo)Result.AsyncState;

//If we've received any sort of message...
{
}
}

private void GetMessage(ClientInfo Client, int DataLength)
{
//Translate the message
string Contents = Encoding.UTF8.GetString(Client.Buffer, 0, DataLength);

int TermLoc = 0;

while (true)
{
TermLoc = Contents.IndexOf(FOOTER);

if (TermLoc == -1 & Contents.Length == 0)
{
return;
}
else if (TermLoc == -1 & Contents.Length > 0)
{
int StartIndex = DataLength - Contents.Length;

Array.Copy(Client.Buffer, StartIndex, Client.Buffer, 0,  Contents.Length);
Client.WorkSocket.BeginReceive(Client.Buffer, StartIndex, BUFFER_SIZE - StartIndex, SocketFlags.None,
return;
}

//Parse message and send it to game loop
PassMessage(Client, Contents.Substring(0, TermLoc));

//Removed received message and look for more
Contents = Contents.Substring(TermLoc + 2, Contents.Length - (TermLoc + 2));
}
}

private void PassMessage(ClientInfo Client, string Message)
{
string[] Split = Message.Split('');
string[] AccountSplit = Split[0].Split('~');
string[] MessageSplit = Split[1].Split('~');

//Message received format = AccountID~CharacterIDect~ect.
RequestModel Request = new RequestModel();
Request.Client = Client.WorkSocket;
Request.AccountName = AccountSplit[0];
Request.CharacterID = AccountSplit[1];
Request.Request = MessageSplit;
}


### #1Theis_Bane

Posted 24 February 2013 - 06:54 PM

Whatever you've seen "floating around the interwebs" ... is not likely to be a reputable source, so proceed with caution there.

Herein lies most of my problems.  NOTHING I've found ANYWHERE on the webs looks anything like what I'm working on right now.  It's like there's some massive conspiracy to prevent new programmers from fully grasping how socket programming works.  I'm worried for you, Kylotan.  The Socket Police are reading this thread.  They know what you've done.  And they are NOT happy.

Okay...so I spent about half an hour staring at your post, trying to get my head around it, trying to work past all the bad or incomplete information I already had...and here's what I've come up with.  It SEEMS to follow everything you've said, but I'm sure you'll see something I don't.  I think, by the time I'm done, I'll have myself an Enterprise-level network protocol at my disposal lol.

private void ReceiveMessage(IAsyncResult Result)
{
ClientInfo thisClient = (ClientInfo)Result.AsyncState;

//If we've received any sort of message...
{
}
}

private void GetMessage(ClientInfo Client, int DataLength)
{
//Translate the message
string Contents = Encoding.UTF8.GetString(Client.Buffer, 0, DataLength);

int TermLoc = 0;

while (true)
{
TermLoc = Contents.IndexOf(FOOTER);

if (TermLoc == -1 & Contents.Length == 0)
{
return;
}
else if (TermLoc == -1 & Contents.Length > 0)
{
int StartIndex = DataLength - Contents.Length;

Array.Copy(Client.Buffer, StartIndex, Client.Buffer, 0,  Contents.Length);
Client.WorkSocket.BeginReceive(Client.Buffer, StartIndex, BUFFER_SIZE - StartIndex, SocketFlags.None,
}

//Parse message and send it to game loop
PassMessage(Client, Contents.Substring(0, TermLoc));

//Removed received message and look for more
Contents = Contents.Substring(TermLoc + 2, Contents.Length - (TermLoc + 2));
}
}

private void PassMessage(ClientInfo Client, string Message)
{
string[] Split = Message.Split('');
string[] AccountSplit = Split[0].Split('~');
string[] MessageSplit = Split[1].Split('~');

//Message received format = AccountID~CharacterIDect~ect.
RequestModel Request = new RequestModel();
Request.Client = Client.WorkSocket;
Request.AccountName = AccountSplit[0];
Request.CharacterID = AccountSplit[1];
Request.Request = MessageSplit;