HTML5¼¼Êõ

½»Í¨ÔËÊ䲿³µÔص¼º½ÏµÍ³¡ª¡ªÖÕ¶ËÈçºÎÓë·þÎñÆ÷ͨÐÅ¡ª¡ªÍæתͨÐÅЭÒé(Ô´ÂëÏÂÔØ) - °¾Ò¹ÓëÑÌ(2)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£º²©¿ÍÔ° 2016-04-23 15:00 ÎÒÒªÆÀÂÛ( )

.tcpPassiveEngine = NetworkEngineFactory.CreateTextTcpPassiveEngine( this .textBox_IP.Text, int .Parse( this .textBox_port.Text), new DefaultTextContractHelper("\0") ); DemoÖÐÓÃ\0À´×÷ΪÏûÏ¢½áÊø±êÖ¾¡£

.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¹²ÓÃÒ»¸ö·þÎñ¶Ë£¡

 

     

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
ÍøÓѵãÆÀ
¬