Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2004, 12:59 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default weird c# or browser behavior

I have a problem with a new C# DHTML chat server I am making. First I'll describe the problem and then i'll post the code.

When I open 3 new instances of IE and connect the first client to localhost:9999 the first client status bar only displays:
"opening page http://localhost:9999"
It does not display "1" in the status bar as expected. But when the 2nd client connects the 1st client displays "2" in the status bar and the 2nd client displays "opening page......" in the status bar.
Only when the 3rd client connects the 2nd client displays "2" in the status bar the first client displays "3" in the status bar and the 3rd client displays "1" in the status bar ( because the server now stoped listening and the program terminated. )
But when I restart the server and reuse the same 3 clients ( without closing them and opening new instances of IE ) the first client after connecting displays "1" in the status bar imediately ( as should be ).
when connecting the 2nd client it imediatly displays "1" in the status bar and the 1st client dispays "2" in the status bar and when i connect the 3rd client the first client displays "3", the 2nd "2" and the 3rd "1" in the status bar.


Why is this behavior. On Netscape the behaviour is somewhat similar.
Or more important how do I solve it, or how do I work around it?


this is the C# code.

// console application
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections;
using System.IO;
using System.Text;

namespace AtomHTTPresponse
{
     class AtomHTTPresponse
     {
          private const int MAX_CONNECTIONS = 3;
          private ArrayList prArrayListHTTPpipes = new ArrayList();
          private TcpListener prTcpListener = new TcpListener( IPAddress.Parse( "127.0.0.1" ), 9999 );
          static void Main(string[] args)
          {
               AtomHTTPresponse lAtomHTTPresponse = new AtomHTTPresponse();
               Thread lThreadListener = new Thread( new ThreadStart( lAtomHTTPresponse.ListenerHandler ) );
               lThreadListener.Start();
          }
          private void ListenerHandler()
          {
               prTcpListener.Start();
               for ( int lCntOuter = 0; lCntOuter < MAX_CONNECTIONS; lCntOuter++ )
               {
                    //lock ( this )
                    //{
                         Thread lThreadListener = new Thread( new ThreadStart( ConnectionHandler ) );
                         lThreadListener.Start();
                    //}
               }
          }
          private void ConnectionHandler()
          {
               TcpClient lTcpClient = prTcpListener.AcceptTcpClient();
               NetworkStream lNetworkStream = lTcpClient.GetStream();
               StreamReader lStreamReader = new StreamReader( lNetworkStream );
               StreamWriter lStreamWriter = new StreamWriter( lNetworkStream );

               HTTPpipe lHTTPpipe = new HTTPpipe( lTcpClient, lNetworkStream, lStreamReader, lStreamWriter );
               prArrayListHTTPpipes.Add( lHTTPpipe );

               lHTTPpipe.WriteToCLient( "<script language=\"javascript\">window.status = 0</script>" );

               for ( int lCntInner = 0; lCntInner < prArrayListHTTPpipes.Count; lCntInner++ )
               {
                    ( prArrayListHTTPpipes[ lCntInner ] as HTTPpipe ).WriteToCLient( "<script language=\"javascript\">window.status = parseInt( window.status ) + 1</script>" );
               }
          }
     }
     class HTTPpipe
     {
          public TcpClient puTcpClient;
          public NetworkStream puNetworkStream;
          public StreamReader puStreamReader;
          public StreamWriter puStreamWriter;
          public char[] puArrCharRequest = new char[256];

          static string cStrResponse = "<script language=\"javascript\">window.status = 0</script>";

          static string cStrHTTPheader = "HTTP/1.1 200 OK\r\n"
               + "Server: Microsoft-IIS/5.0\r\n"
               + "Date: Wed, 9 jan 2004 19:59:09 GMT\r\n"
               + "X-Powered-By: ASP.NET\r\n"
               + "Content-Type: text/html\r\n"
               + "Set-Cookie: ASPSESSIONIDASQSSARR=CCOBBLCBOLKOECFIANBGOBAI; path=/\r\n" // let it be for now. redundancy will be removed at a later time
               + "Cache-control: private\r\n\r\n";

          public HTTPpipe( TcpClient iTcpClient, NetworkStream iNetworkStream, StreamReader iStreamReader, StreamWriter iStreamWriter )
          {
               puTcpClient = iTcpClient;
               puNetworkStream = iNetworkStream;
               puStreamReader = iStreamReader;
               puStreamWriter = iStreamWriter;
               puStreamReader.Read( puArrCharRequest, 0, puArrCharRequest.Length ); // do nothing with the request but now we know we dont send a response before the request has been fully received.
               WriteToCLient( cStrHTTPheader );
               WriteToCLient( cStrResponse );
          }
          public void WriteToCLient( string iStrResponse )
          {
               puStreamWriter.Write( iStrResponse );
               puStreamWriter.Flush();
          }
          public void Close()
          {
               puTcpClient.Close();
          }
     }
}

Regards,

Ed Tijgen





Similar Threads
Thread Thread Starter Forum Replies Last Post
erratic cursor behavior Tim Johnson Access 4 November 27th, 2007 07:30 AM
Weird post back behavior mjhoagland Classic ASP Professional 3 December 26th, 2006 10:31 AM
AJAX Webservice behavior Sopi.Dohl Ajax 1 September 19th, 2006 06:06 AM
Launch default browser in a new browser window haiying Beginning VB 6 1 August 30th, 2005 05:48 PM
shows weird page name in the browser zulf Dreamweaver (all versions) 3 February 12th, 2004 07:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.