ÓÃC#µØRaw SocketÍê³ÉÍøÂç·â°ü¼àÊÓ

ÁËÒì²½»Øµ÷º¯ÊýCallReceive£¬²¢°Ñ½ÓÊÕµ½µÄÍøÂçÊý¾ÝÁ÷´«¸øreceive_buf_bytes£¬ÕâÑù¾Í¿ÉÓÃÒ»¸ö´øÓÐÒì²½²Ù×÷µÄ½Ó¿Ú²ÎÊýµÄÒì²½»Øµ÷º¯Êý²»¶ÏµØ½ÓÊÕÊý¾Ý°ü£º

private void CallReceive(IAsyncResult ar)//Òì²½»Øµ÷ { int received_bytes; received_bytes = socket.EndReceive(ar); Receive(receive_buf_bytes, received_bytes); if (KeepRunning) Run(); }

´Ëº¯Êýµ±¹ÒÆð»ò½áÊøÒì²½¶ÁÈ¡ºóÈ¥½ÓÊÕÒ»¸öеÄÊý¾Ý°ü£¬ÕâÑùÄܱ£Ö¤ÈÃÿһ¸öÊý¾Ý°ü¶¼Äܹ»±»³ÌÐò̽²âµ½¡£

ÏÂÃæͨ¹ýÉùÃ÷´úÀíʼþ¾ä±úÀ´ÊµÏÖºÍÍâ½çµÄͨÐÅ£º

public delegate void PacketArrivedEventHandler(Object sender, PacketArrivedEventArgs args); //ʼþ¾ä±ú£º°üµ½´ïʱÒý·¢Ê¼þ public event PacketArrivedEventHandler PacketArrival;//ÉùÃ÷ʱ¼ä¾ä±úº¯Êý

ÕâÑù¾Í¿ÉÒÔʵÏÖ¶ÔÊý¾Ý°üÐÅÏ¢µÄ»ñÈ¡£¬²ÉÓÃÒì²½»Øµ÷º¯Êý£¬¿ÉÒÔÌá¸ß½ÓÊÕÊý¾Ý°üµÄЧÂÊ£¬²¢Í¨¹ý´úÀíʼþ°Ñ·â°üÐÅÏ¢´«µÝµ½Íâ½ç¡£¼ÈÈ»ÄÜ°ÑËùÓеķâ°üÐÅÏ¢´«µÝ³öÈ¥£¬¾Í¿ÉÒÔʵÏÖ¶ÔÊý¾Ý°üµÄ·ÖÎöÁË£º£©²»¹ýRawSocketµÄÈÎÎñ»¹Ã»ÓÐÍ꣬×îºó²»ÒªÍûÁ˹رÕÌ×½Ó×Ö°¡£º

public void Shutdown() //¹Ø±Õraw socket { if(socket != null) { socket.Shutdown(SocketShutdown.Both); socket.Close(); } }

ÒÔÉϽéÉÜÁËRawSocketÀàͨ¹ý¹¹ÔìIPÍ·»ñÈ¡ÁË°üÖеÄÐÅÏ¢£¬²¢Í¨¹ýÒì²½»Øµ÷º¯ÊýʵÏÖÁËÊý¾Ý°üµÄ½ÓÊÕ£¬²¢Ê¹ÓÃʱ¼ä´úÀí¾ä±úºÍ×Ô¶¨ÒåµÄÊý¾Ý°üÐÅϢʼþÀà°ÑÊý¾Ý°üÐÅÏ¢·¢ËͳöÈ¥£¬´Ó¶øʵÏÖÁËÍøÂçÊý¾Ý°üµÄ¼àÊÓ£¬ÕâÑùÎÒÃǾͿÉÒÔÔÚÍⲿÌí¼ÓһЩº¯Êý¶ÔÊý¾Ý°ü½øÐзÖÎöÁË¡£

ÁªÏµ¿Í·þ£º779662525#qq.com(#Ì滻Ϊ@)