在线等,关于C# TCP/IP Socket 的 输据传输问题!!!!!!!!
大家好 ,本人现在在做一个家庭安全系统,用TCP/IP Socket 写了 Client 和 server 两个终端。房子的模型(装有几个感应器),当感应器一触发,那么server 端会发出 数据,client 会接受 并作出相应的判断(播放警报音乐文件并发送email)。有些基本的都没有问题了,现在就是当我实际测试的时候,当我的 client接收到server发送来得数据,并要播放音乐文件和发送email时不能正常工作。
以下列出:
1:音乐文件播放不完全(断断续续的,并每次都是从头开始,之间间隙只有零点几秒),我使用API函数播放wav文件,最初使用简单的按钮测试没有问题。
--------------------------------------------------------------------音乐播放的code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace smarthome
{
     class sound
     {
         [Flags]   
    public  enum  PlaySoundFlags  :  int     
   {   
    SND_SYNC  =  0x0000,    /*  play  synchronously  (default)  */  //同步   
    SND_ASYNC  =  0x0001,    /*  play  asynchronously  */  //异步   
    SND_NODEFAULT  =  0x0002,    /*  silence  (!default)  if  sound  not  found  */   
    SND_MEMORY  =  0x0004,    /*  pszSound  points  to  a  memory  file  */   
    SND_LOOP  =  0x0008,    /*  loop  the  sound  until  next  sndPlaySound  */   
    SND_NOSTOP  =  0x0010,    /*  don't  stop  any  currently  playing  sound  */   
    SND_NOWAIT  =  0x00002000,  /*  don't  wait  if  the  driver  is  busy  */   
    SND_ALIAS  =  0x00010000,  /*  name  is  a  registry  alias  */   
    SND_ALIAS_ID  =  0x00110000,  /*  alias  is  a  predefined  ID  */   
    SND_FILENAME  =  0x00020000,  /*  name  is  file  name  */   
    SND_RESOURCE  =  0x00040004    /*  name  is  resource  name  or  atom  */   
   }     
   [DllImport("winmm.dll")]   
   public  static  extern  bool  PlaySound(  string  szSound,  IntPtr  hMod,  PlaySoundFlags  flags  );   
  }     
  public  class  Sound     
  {   
//播放
   public  static  void  Play(  string  strFileName  )   
   {   
    switch(strFileName)   
    {
        case "error": strFileName = @"C:\Documents and Settings\Qiu Wei\My Documents\Visual Studio 2005\Projects\smarthome\smarthome\Resources\1.wav"; break;
        case "warning": strFileName = @"C:\Documents and Settings\Qiu Wei\My Documents\Visual Studio 2005\Projects\smarthome\smarthome\Resources\2.wav"; break;   
    /* case  "fall":  strFileName=@"..\..\sound\fall.WAV";                  break;           
     case  "huiqi":  strFileName=@"..\..\sound\huiqi.WAV";              break;   
     case  "huiqiend":  strFileName=@"..\..\sound\huiqiend.WAV";  break;   
     case  "jiangjun":  strFileName=@"..\..\sound\jiangjun.WAV";  break;   
     case  "kill":  strFileName=@"..\..\sound\kill.WAV";                  break;   
     case  "win":  strFileName=@"..\..\sound\win.WAV";                      break;   
     case  "move":  strFileName=@".\start.WAV";                  break;   
     case  "hold":  strFileName=@".\stop.WAV";                  break;   
     case  "no":  strFileName=@"..\..\sound\no.WAV";                          break;   
     case  "popup":  strFileName=@"..\..\sound\popup.WAV";              break;   
     case  "mayfall":  strFileName=@"..\..\sound\mayfall.WAV";      break;  */
 &nbs