// here is the problem if i am debuging it with break point in visual studion i am getting the result. but if i am running the application exe it takes time to read the response from socket.// to avoid this i ahve used thread.sleep
but its not a solution becasue of performance. // same code is running on the windows server 2003 properly// presenly im running my service on windows server 2008 and client is also on windows server 2008. // my service is ruuing properly
.problem is in only client. static void Connect()
{
bool blnRc = false;
string strHostName = "153.71.83.126";
//intPort = Convert.ToInt32(strPort, 10);
IPAddress objectIPAddress;
Socket objectSocket;
int intTimeOutCounter = 0, intTcpBufferSize = 5000, intAvailable;
byte[] byteBuf = new byte[intTcpBufferSize];
int intCnt = 0;
int intRecvCnt = 0;
objectIPAddress = Dns.GetHostEntry(strHostName).AddressList[Dns.GetHostEntry(strHostName).AddressList.Length - 1];
IPEndPoint EPhost = new IPEndPoint(objectIPAddress, 5350);
try
{
if (objectIPAddress.AddressFamily == AddressFamily.InterNetwork)
objectSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
else
objectSocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
objectSocket.Connect(EPhost);
string strCmd = "<?xml version='1.0' ?>\n<loginmanager sessionname='session1' applname='security' sectoken=''>\n <logout/>\n </loginmanager>\n";
byte[] array = Encoding.UTF8.GetBytes(strCmd.ToCharArray());
objectSocket.Send(array,array.Length,SocketFlags.None);
DateTime dt = DateTime.Now;
do
{
Thread.Sleep(1000);
// here is the problem if i am debuging it with break point in visual studion i am getting the result. but if i am running the application exe it takes time to read the response from socket.
// to avoid this i ahve used thread.sleep but its not a solution becasue of performance.
// same code is running on the windows server 2003 properly
// presenly im running my service on windows server 2008 and client is also on windows server 2008.
Console.WriteLine("In Loop" + objectSocket.Available);
intAvailable=objectSocket.Available;
if(objectSocket.Available>0)
intCnt = objectSocket.Receive(byteBuf, 0, intAvailable < intTcpBufferSize ? intAvailable : intTcpBufferSize, SocketFlags.None);
} while (intAvailable <= 0);
Console.WriteLine(DateTime.Now.Subtract(dt));
objectSocket.Close();
Console.WriteLine("after result");
Console.WriteLine(UnicodeEncoding.UTF8.GetString(byteBuf, 0, intCnt));
Console.ReadLine();
}
catch (Exception ex)
{
}
}