notes.txt 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. Interface with DatagramSocket
  2. http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.datagramsocket
  3. Set the event handler
  4. http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.datagramsocket.messagereceived
  5. Then bind (asynch):
  6. http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.datagramsocket.bindendpointasync
  7. Close socket:
  8. http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.datagramsocket.close
  9. SystemAddress to / from IPV4, IPV6
  10. Domain name to IP lookup
  11. Lots of info here:
  12. Do not use ConnectAsynch, because you cannot get datagrams from any remote address, only those you have connected to.
  13. http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.datagramsocket
  14. Send:
  15. When sending to a new system, use GetOuputStreamAsynch http://msdn.microsoft.com/en-us/library/windows/apps/hh701265. When it completes, send the data using
  16. DataWriter http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.streams.datawriter.aspx
  17. Use WriteBuffer, then StoreAsynch.
  18. http://msdn.microsoft.com/en-us/library/windows/apps/hh701265
  19. For each connection, need GetOutputStreamAsync, which specifies a hostname (IP address) and port.
  20. Set TTL:
  21. Use control:
  22. http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.datagramsocketcontrol#properties
  23. Receive:
  24. http://msdn.microsoft.com/en-us/library/windows/apps/BR241344
  25. DatagramSocket^ listener = ref new DatagramSocket();
  26. ListenerContext^ listenerContext = ref new ListenerContext(rootPage, listener);
  27. listener->MessageReceived += ref new TypedEventHandler<DatagramSocket^, DatagramSocketMessageReceivedEventArgs^>(listenerContext, &ListenerContext::OnMessage);
  28. Sample:
  29. http://code.msdn.microsoft.com/windowsapps/DatagramSocket-sample-76a7d82b
  30. http://blogs.msdn.com/b/trycatchfinally/archive/2012/09/06/welcome.aspx
  31. Closed forum questions:
  32. Datagram Socket receive from any sender
  33. http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/2d732e1b-a9a1-4195-bfe5-216a75fb4319/
  34. DatagramSocket: When I get MessageReceived, how do I actually read the data and who it was from?
  35. http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/ae568041-a080-4194-a783-94b6bc48852d/
  36. DatagramSocket; GetOutputStreamAsync asynch?
  37. http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/cbbf610a-bcff-47f1-b930-e79c36a5f53e/
  38. Open forum question:
  39. http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/ce47bbae-80a0-460c-b738-3a752b0d4d3a
  40. Programming language is C++/CX
  41. http://msdn.microsoft.com/en-us/library/windows/apps/hh699871.aspx
  42. Concurrency task
  43. http://msdn.microsoft.com/EN-US/library/hh750113(VS.110).aspx
  44. http://blogs.microsoft.co.il/blogs/pavely/archive/2012/06/25/windows-8-metro-c-cx-vs-c.aspx
  45. http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/8a72dda7-dd25-4356-b830-f33b35784af0
  46. How to callback to existing C++ from C++/CX?
  47. I have a large body of C++ code that I am trying to integrate with Windows 8 Store. In the existing code, I use a pure virtual interface for when a network message arrives
  48. class RNS2EventHandler {
  49. virtual void OnRNS2Recv(RNS2RecvStruct *recvStruct)=0;
  50. };
  51. class RakPeer : public RakPeerInterface, public RNS2EventHandler {
  52. virtual void OnRNS2Recv(RNS2RecvStruct *recvStruct) {DoStuff();}
  53. };
  54. In Windows Store 8, I get this callback when a network message arrives
  55. public ref class ListenerContext sealed
  56. {
  57. public:
  58. void OnMessage(Windows::Networking::Sockets::DatagramSocket^ socket, Windows::Networking::Sockets::DatagramSocketMessageReceivedEventArgs^ eventArguments) {
  59. // Need to call the C++ callback
  60. }
  61. }
  62. If I try putting a RNS2EventHandler* inside ListenerContext the compiler complains that I can't put C++ types inside a C++/CX class.
  63. So how do I implement a callback to notify C++ when ListenerContext::OnMessage occurs? As a last resort I can poll ListenerContext in a thread from the C++ code, but that ruins performance and the whole point of a callback. But I'll do it if there is no straightforward alternative.
  64. Thanks in advance.
粤ICP备19079148号