Home › Forums › Support › handle received packets › Reply To: handle received packets
I am creating an emulator for a game called Priston Tale. It works like every other winsock application. It just sends byte[] to the server, which I parse according the opcode and then I answer with another byte[]. Not much complicated.
This is how I did to receive the packets, using TcpClient:
`/// <summary>
/// Waits until a packet is received from client
/// </summary>
void Run(object stateInfo)
{
var data = new byte[0x1000];
byte[] packet;
var read = 0;
while (true)
{
try { read = stream.Read(data, 0, 0x1000); }
catch (Exception)
{
Clients.pInfo.Remove(this.key);
break;
}
if (read == 0)
{
Clients.pInfo.Remove(this.key);
break;
}
packet = new byte[read];
Array.ConstrainedCopy(data, 0, packet, 0, read);
packets.Queue(packet, this);
}
client.Close();
}`
the stream variable is obtained using tcpclient.GetStream() method.