.tcpPassiveEngine = NetworkEngineFactory.CreateTextTcpPassiveEngine(this.textBox_IP.Text, int.Parse(this.textBox_port.Text), new DefaultTextContractHelper("\0"));
DemoÖÐÓÓ\0”À´×÷ΪÏûÏ¢½áÊø±êÖ¾¡£ÎÒÃÇÖªµÀ£¬ÏûÏ¢½áÊø·ûÊÇÎÒÃÇÈËΪµÄ¼Óµ½ÏûϢβ²¿£¬¶øÕæÕýµÄÏûÏ¢ÊDz»¾ß±¸ÕâÑùµÄÄÚÈݵġ£ËùÒÔÔÚÊÕµ½ÏûϢʱÎÒÃÇÐèÒªÌÞ³ýÕâ¸ö½áÊø·û£¬Ò²¾ÍÊǽâ·â¡£
void tcpPassiveEngine_MessageReceived(System.Net.IPEndPoint serverIPE, byte[] bMsg) { string msg = System.Text.Encoding.UTF8.GetString(bMsg); //ÏûϢʹÓÃUTF-8±àÂë msg = msg.Substring(
¸½£ºÎı¾ÐÒédemoÔ´ÂëÏÂÔØ
Áù.¶þ½øÖÆÐÒéDemoʵÏÖʾÀý
// ÕªÒª: IStreamContractHelper { // ÕªÒª: MessageHeaderLength { get; } // ÕªÒª: // ´ÓÏûϢͷÖнâÎö³öÏûÏ¢ÌåµÄ³¤¶È£¨×¢Ò⣬²»ÊÇÕû¸öÏûÏ¢µÄ³¤¶È£¬¶øÊDz»°üº¬ÏûϢͷµÄBodyµÄ³¤¶È£©¡£ // // ²ÎÊý: // head: ParseMessageBodyLength(byte[] head); }
Îı¾ÐÒéÖúÊÖ½Ó¿Ú¶¨ÒåÁ˲ÉÓÃÎı¾ÐÒéµÄ×î»ù±¾µÄ¹æ·¶——ÏûϢͷ¶¨³¤£¬´ÓÏûϢͷÖÐÄܹ»½âÎö³öÏûÏ¢Ì峤¶È¡£½ÓÏÂÀ´ÎÒÃÇ¿´Ò»¸ö¸Ã½Ó¿ÚµÄ¼òµ¥ÊµÏÖ£ºÏûϢͷ¹æ¶¨Îª8¸ö×Ö½Ú£¬ÆäÖÐÍ·4¸ö×Ö½Ú´æ·ÅÒ»¸öintÀàÐ͵ÄÏûÏ¢Ì峤¶È¡£
public class StreamContractHelper : IStreamContractHelper { public int MessageHeaderLength { get { return 8; } } public int ParseMessageBodyLength(byte[] head) { return BitConverter.ToInt32(head, 0); } }
ÎÒÃǽ«Æä×¢ÈëͨÐÅÒýÇ棬ÒýÇæ¼´¿Éʶ±ðÏûϢͷ¡¢È¡³öÏûÏ¢Ì峤¶ÈÀ´·Ö¸î³öÒ»¸ö¸öÏûÏ¢¡£
.tcpPassiveEngine = NetworkEngineFactory.CreateStreamTcpPassivEngine(this.textBox_IP.Text, int.Parse(this.textBox_port.Text), new StreamContractHelper());
¸½£º¶þ½øÖÆÐÒédemoÔ´ÂëÏÂÔØ
Æß.×ܽá
±¾ÎÄÖ¼ÔÚ½éÉÜÎı¾ÐÒéÉè¼ÆµÄÒ»°ã·½·¨£¬Í¨¹ý¶ÔÓÚÎı¾ÐÒéÓë¶þ½øÖÆÐÒéµÄ±¾ÖʵÄÕÆÎÕ£¬´ó¼Ò¾ÍÄܸù¾Ýʵ¼ÊµÄÐèÒªÀ´Õë¶ÔÐÔµÄʵÏÖÆäͨÐÅÐÒéÁË¡£´ó¼Ò¿ÉÒÔ¸ù¾ÝÕâ¸öÒ»°ãµÄ·½·¨×Ô¼ºÀ´ÊµÏÖÒ»¿ªÊ¼ÎÒ¸ø³öÀ´µÄÎÀÐǶ¨Î»ÏµÍ³µÄͨÐÅÐÒé¡£
ÓÐÐí¶àÐèÒªÓëÓ²¼þÉ豸ͨÐŵÄÓ¦Óã¬ÖîÈçÓëGPSÉ豸ͨÐÅ¡¢Ó빤³§³µ¼äµÄһЩµ¥Æ¬»úÉ豸ͨÐÅ¡¢ÓëÎïÁªÍøÉ豸ͨÐŵȵȣ¬´ó¼ÒÖ»ÒªÕÆÎÕÁËÕâЩÉ豸µÄͨÐÅÐÒ飬»ò²ÉÓÃÎı¾ÐÒé»ò²ÉÓöþ½øÖÆÐÒ飬½«ÆäʵÏÖ£¬ÄÇôͨÐŵÄÎÊÌâ¾ÍÓÈжø½âÁË£¡
×îºó£¬Ëæ×ÅHTML5 WebSocket¼¼ÊõµÄÈÕÒæ³ÉÊìÓëÆÕ¼°£¬B/S¼Ü¹¹µÄÓ¦ÓÃÓÚC/S¼Ü¹¹µÄÓ¦ÓõÄͨÐÅÒ²Öð½¥×ßÏò´óһͳ¡£ÓÐÐËȤµÄÅóÓÑ¿ÉÒԲο¼£º´òͨB/SÓëC/S£¡ÈÃHTML5 WebSocketÓë.NET Socket¹²ÓÃÒ»¸ö·þÎñ¶Ë£¡
¡¡