// Initialize Chat application from HTTP request
	ns_start_transaction("chat_xhtml");
    ns_web_url ("chat_xhtml",
        "URL=https://127.0.0.1:4444/examples/websocket/chat.xhtml",
        "HEADER=Upgrade: websocket",
        "HEADER=Connection: Upgrade"
    );

    ns_end_transaction("chat_xhtml", NS_AUTO_STATUS);
	
    ns_page_think_time(1.091); 		// Think time to add  delay between two actions/steps.

	
    int msg_len;  // Length of the message received. If no message, it will return 0.
	char *msg;    // Pointer to the buffer containing the message received. If no message received((after timeout)), it will return NULL.
	
    // Creates connection with Chat application 
	ns_start_transaction("ws_chat_connect");
    ns_web_websocket_connect("ID=1",
        "URI=wss://127.0.0.1:4444/examples/websocket/chat"
    );
    ns_end_transaction("ws_chat_connect", NS_AUTO_STATUS);
	
    ns_page_think_time(1.091); 		// T Think time to add  delay between two actions/steps.
	
	

    // Reads messages from chat application
	ns_start_transaction("ws_chat_read_start_msg");
    msg = ns_web_websocket_read(1, 1000, &msg_len);
    ns_end_transaction("ws_chat_read_start_msg", NS_AUTO_STATUS);
	
    ns_page_think_time(1.091); 		//  Think time to add  delay between two actions/steps.


    // Prints received message on output logs.	
	fprintf(stdout, "Received message [len = %d] = %s\n", msg_len, msg);


    // Sends messages on chat application 		
	ns_start_transaction("ws_chat_send_msg");
    ns_web_websocket_send("ID=1",
        "Buffer=Hi, I have placed an order and its not delivered yet please check and get it delivered ASAP",
        "IsBinary=0"
    );
    ns_end_transaction("ws_chat_send_msg", NS_AUTO_STATUS);

    ns_page_think_time(1.091); 		//  Think time to add  delay between two actions/steps..
		
    // Reads messages from chat application
	ns_start_transaction("ws_chat_read_msg");
    msg= ns_web_websocket_read(1, 1000, &msg_len);
    ns_end_transaction("ws_chat_read_msg", NS_AUTO_STATUS);	

    ns_page_think_time(1.091); 		//  Think time to add  delay between two actions/steps.
	

   // Closes connection with Chat application
	ns_start_transaction("ws_chat_close");	
    ns_web_websocket_close("ID=1",
        "Code=1000",
        "Reason=NORMAL CLOSURE",
    );
	ns_end_transaction("ws_chat_close", NS_AUTO_STATUS);
	ns_page_think_time(1.091); 		//  Think time to add  delay between two actions/steps.	
