Socket Programming
-
Hi guys, I am trying to update an old application that was designed by another programmer. I am not very sharp at C# and need your help. Can you please help me understand the following code that is in the windows service IPHostEntry hostEntry=Dns.Resolve(m_sServerAddr); IPAddress ipAddress = hostEntry.AddressList[0]; IPEndPoint ipEndPoint = new IPEndPoint(ipAddress,m_nPort); m_svSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); m_svSocket.Bind(ipEndPoint); m_svSocket.Listen(10); while(true) { Socket rtSocket=m_svSocket.Accept(); if(rtSocket.Connected) { TD.WaitCallback myCallBack = new TD.WaitCallback(ProcessClientRequest); TD.ThreadPool.QueueUserWorkItem(myCallBack,rtSocket); } } ProcessClientRequest has a bunch of functions called like getschedule from database etc. I am trying to force Processclientrequest to reload the schedule from the database without restarting the service. Please help.
Sameer
-
Hi guys, I am trying to update an old application that was designed by another programmer. I am not very sharp at C# and need your help. Can you please help me understand the following code that is in the windows service IPHostEntry hostEntry=Dns.Resolve(m_sServerAddr); IPAddress ipAddress = hostEntry.AddressList[0]; IPEndPoint ipEndPoint = new IPEndPoint(ipAddress,m_nPort); m_svSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); m_svSocket.Bind(ipEndPoint); m_svSocket.Listen(10); while(true) { Socket rtSocket=m_svSocket.Accept(); if(rtSocket.Connected) { TD.WaitCallback myCallBack = new TD.WaitCallback(ProcessClientRequest); TD.ThreadPool.QueueUserWorkItem(myCallBack,rtSocket); } } ProcessClientRequest has a bunch of functions called like getschedule from database etc. I am trying to force Processclientrequest to reload the schedule from the database without restarting the service. Please help.
Sameer
Wow, looks more like a coding horror to me... People run that code on their PC??
-Spacix All your skynet questions[^] belong to solved
-
Wow, looks more like a coding horror to me... People run that code on their PC??
-Spacix All your skynet questions[^] belong to solved
no the service is installed on the server. It has run and currently runs great with no problems. What do you mean by coding horror? Also, the attached code is called by the timer. Here is the full function. private void StartTimerAndServerSocket() { Writ2ErrLog("Service Timer Initialized"); string sErr="Application is ready for processing"; try { Writ2ErrLog(sErr); m_tMonitor = new TD.Timer(new TD.TimerCallback(MonitorFunc),1, 0,45000);//45 sec if(m_sServerAddr==string.Empty) { m_sServerAddr=Dns.GetHostName(); } if(m_nPort==-1) { m_nPort=1024; } IPHostEntry hostEntry=Dns.Resolve(m_sServerAddr); IPAddress ipAddress = hostEntry.AddressList[0]; IPEndPoint ipEndPoint = new IPEndPoint(ipAddress,m_nPort); m_svSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); m_svSocket.Bind(ipEndPoint); m_svSocket.Listen(10); while(true) { Socket rtSocket=m_svSocket.Accept(); if(rtSocket.Connected) { TD.WaitCallback myCallBack = new TD.WaitCallback(ProcessClientRequest); TD.ThreadPool.QueueUserWorkItem(myCallBack,rtSocket); } } } catch(Exception ex) { m_svSocket.Close(); m_tMonitor.Dispose(); sErr="Start Error " + ex.Message; } finally { if(sErr!=string.Empty) { Debug.WriteLine(sErr); Writ2ErrLog(sErr); } }
Sameer