Basic Socket Programming in C#

using System;
using System.Net.Sockets;
using System.Text;
namespace Cons
{
 class Program
 {
  static void Main(string[] args)
  {
   TcpListener serverSocket = new TcpListener(8888);
   int requestCount = 0;
   TcpClient clientSocket = default(TcpClient);
   serverSocket.Start();
   Console.WriteLine(" >> Server Started");
   clientSocket = serverSocket.AcceptTcpClient();
   Console.WriteLine(" >> Accept connection from client");
   requestCount = 0;
   while ((true))
   {
    try
    {
     requestCount = requestCount + 1;
     NetworkStream networkStream = clientSocket.GetStream();
     byte[] bytesFrom = new byte[10025];
     networkStream.Read(bytesFrom, 0,
     (int)clientSocket.ReceiveBufferSize);
     string dataFromClient =
     System.Text.Encoding.ASCII.GetString(bytesFrom);
     dataFromClient = dataFromClient.Substring(0,
     dataFromClient.IndexOf("$"));
     Console.WriteLine(" >> Data from client - " +
     dataFromClient);
     string serverResponse = "Server response " +
     Convert.ToString(requestCount);
     Byte[] sendBytes =
     Encoding.ASCII.GetBytes(serverResponse);
     networkStream.Write(sendBytes, 0, sendBytes.Length);
     networkStream.Flush();
     Console.WriteLine(" >> " + serverResponse);
    }
    catch (Exception ex)
    {
     Console.WriteLine(ex.ToString());
    }
   }
   clientSocket.Close();
   serverSocket.Stop();
   Console.WriteLine(" >> exit");
   Console.ReadLine();
  }
 }
}

Oppourtunity Count for MSCRM4

This is a javascript which calculates the number of opportunities and displays in the navigation.
// OPPOURTUNITY COUNT_______________________
var OPPOURTUNITY_COUNT_ACC = function () {
if (crmForm.FormType != 1) {
var objectidguid = crmForm.ObjectId;
try{        
var OpprNavTxt = document.getElementById('navOpps').getElementsByTagName('NOBR')[0].innerText;
}
catch(e){ return; }

var fxml = "<fetch mapping='logical'><entity name='account'><no-attrs/><filter type='and'><condition attribute='accountid' operator='eq' value='" + objectidguid + "'/></filter><link-entity name='opportunity' from='customerid' to='accountid'><attribute name='name'/></link-entity></entity></fetch>";

var soap7 = "";
soap7 += GenerateAuthenticationHeader();
soap7 += "";
soap7 += fxml;
soap7 += "";
var XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
XmlHttp.open("POST", "/mscrmservices/2007/CrmService.asmx", false);
XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
XmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
XmlHttp.setRequestHeader("Content-Length", soap7.length);
XmlHttp.send(soap7);
var resultText = XmlHttp.responseXML.text;
var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
oXmlDoc.async = false;
oXmlDoc.loadXML(resultText);
var results = oXmlDoc.getElementsByTagName('result');
var no_of_opp = results.length;
document.getElementById('navOpps').getElementsByTagName('NOBR')[0].innerText = OpprNavTxt + " (" + no_of_opp + ")";
}
};