void HandlePacket(
PacketType pkt
)
Sub HandlePacket (
pkt As PacketType
)
void HandlePacket(
PacketType pkt
)
abstract HandlePacket :
pkt : PacketType -> unit
bool done = false;
while (!done) {
PacketType pkt = ml.NextPacket();
if (ml.OnPacketArrived(pkt))
ml.HandlePacket(pkt);
switch (pkt) {
case PacketType.Return:
// read and handle contents of ReturnPacket ...
done = true;
break;
case PacketType.Text:
// read and handle contents of TextPacket ...
break;
.. etc for other packet types
}
ml.NewPacket();
}
To remind again, writing your own packet loop like this is strongly discouraged. Use WaitForAnswer, WaitAndDiscardAnswer, or one of the "EvaluateTo" methods instead. These methods hide the packet loop within them. If you want more information about what packet types arrive and their contents, simply use the PacketArrived event.
An example of the special type of packets that your packet loop might encounter is PacketType.Call. Encountering a PacketType.Call means that Wolfram Language code is trying to call into .NET using the mechanism described in Part 1 of the .NET/Link User Guide. Only the internals of .NET/Link know how to manage these callbacks, so the HandlePacket method provides a means to invoke this handling for you.If you are using WaitForAnswer, WaitAndDiscardAnswer, or any of the "EvaluateTo" methods, and therefore not writing your own packet loop, you do not need to be concerned with HandlePacket.
MathLinkException | On any MathLink error. |