基于c局域网视频聊天设计(编辑修改稿)内容摘要:

ncCallback( OnReceivedData )。 ( , 0, , , receiveData, s )。 // (Re)Setup a callback to be notified of connection requests (new AsyncCallback( OnConnectRequest ) , listener )。 } else { 12 // If we are in shutdown mode, DON39。 T add // the connection to the array, DON39。 T setup // the async listen, and DO set the event // to say we are done. ()。 } } } // Client has sent data, or has disconnected private void OnReceivedData( IAsyncResult ar ) { // Socket was the passed in object SockWrapper s = (SockWrapper)。 lock (this) { if (!m_bShuttingDown) { // Check if we got any data try { int nBytesRec = ( ar )。 if( nBytesRec 0 ) { if (DataReceived != null) DataReceived(this, ref , ref , nBytesRec)。 // Restablish the callback AsyncCallback receiveData = new AsyncCallback( OnReceivedData )。 ( , 0, , , receiveData, s )。 } else { // If no data was received then the connection is probably dead RemoveConnection(s)。 } } catch { RemoveConnection(s)。 } 13 } } } // Remove a connection from the list of active connections private void RemoveConnection(SockWrapper s) { try { ( )。 ()。 } catch {} // Remove it from the array try { ( s )。 } catch {} // Fire the Disconnected event if (Disconnected != null) Disconnected(this, ref )。 } // Wrapper for each client (stored in m_aryClients) internal class SockWrapper { // The buffer is used by receive public Socket Client。 public byte [] byBuff。 public object obj。 public SockWrapper(Socket client) { Client = client。 byBuff = new byte[256]。 obj = new object()。 } } } public delegate void TcpConnected(Object sender, ref object o)。 14 public delegate void TcpSend(Object sender, ref object o, ref bool b)。 public delegate void TcpReceive(Object sender, ref object o, ref byte [] b, int ByteCount)。 } WebCamService 类 : namespace WebCamService { public class WebCamService : ServiceBase { region Required Service Related Methods private ponents = null。 public WebCamService() { InitializeComponent()。 } private void InitializeComponent() { ponents = new ()。 = WebCamService。 } protected override void Dispose( bool disposing ) { if( disposing ) { if (ponents != null) { ()。 } } ( disposing )。 } endregion [STAThread] public static void Main(string[] args) { = Main thread。 WebCamService ServiceToRun = new WebCamService()。 15 if ( ) { ()。 } else { = false。 (ServiceToRun)。 } } region Member Variables private const int MAXOUTSTANDINGPACKETS = 3。 /// summary /// The thread will run the job. /// The job is the Method Run() below /// /summary protected Thread thread = null。 private ManualResetEvent ConnectionReady。 private volatile bool bShutDown。 private volatile int iConnectionCount。 endregion /// summary /// Set things in motion so your service can do its work. /// 为了服务器可以工作而设置的选项 /// /summary protected override void OnStart(string[] args) { ThreadStart starter = new ThreadStart(Run)。 //实例化进程 thread = new Thread(starter)。 ()。 } /// summary /// Stop this service. /// 停止服务 /// The Run() Method tests for this thread state each second /// 每秒都为这个进程启动方法测试 /// /summary protected override void OnStop() { 16 // Set exit condition //设置退出状态 bShutDown = true。 // Need to get out of wait //需要退出等待 ()。 } public void Run() { const int VIDEODEVICE = 0。 // zero based index of video capture device to use const int FRAMERATE = 15。 // Depends on video device caps. Generally 430. const int VIDEOWIDTH = 640。 // Depends on video device caps const int VIDEOH。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。