Servlets :: Event Stream Does Not Stop After JSP Exits

Dec 5, 2014

I have a servlet which sends HTML5 server sent events to the jsp client. The servlet sends data to the client every one second. The jsp client instantiates a new eventsource and recieves the data. When the window is about to close, the jsp client closes eventsource at the "beforeunload" event (shown in the code below).

However, I have noticed that even after the client closes the eventsource and the browser exits, the server continues sending data. As far as the documentation on eventsource goes, using eventsource.close() is enough to stop client from reconnecting to the server and the server will stop sending any further push notifications.

Why the server does not stop sending push notifications even after eventsource.close() and the browser exit? Do I write any other piece of code to notify the server to stop sending data once client exits?

Pasted below are the servlet (server ) code and the client code.

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

[Code] .....

View Replies


ADVERTISEMENT

Java-8 :: How To Stop Infinite Stream

May 26, 2014

I have a Stream instace which produces values using an infinite Supplier (it supplies values taken from an electronic sensor -- so unless the battery is low, the sensor will provide "for ever").

The stream is processed by a Collector using Stream.collect() (e. g. imagine that the values from the sensor should be averaged; in fact what it does is a bit more compliacted maths).

The problem is that the collector does not produce a result but hangs up, as the supplier does never stop providing more sensor values.

So what I need is a limitation rule that stops the stream. While there is a Stream.limit(long) method, it actually does not solve my problem as in my case it is not practical to stop after a particular count, while I actually want to stop streaming when the sensor value exceeds a particular limit etc. (hence, voids an arbitrary rule).
 
To sum up, what I need is Stream.limit(Predicate), i. e. the stream will stopped once the predicate becomes true.
 
Unfortunately I did not find anything like that in JRE 8.
 
Is that planned for JRE 8.1 or JRE 9.0? Or is there a known (and sophisticated) workaround?

View Replies View Related

Servlets :: Write Output Stream After Response Has Been Committed By Server

Aug 6, 2014

When do i get IllegalStateException in servlets.What it means by trying to write to the output stream (response) after the response has been committed by server. What it means by committing response and uncommitting response. cannot i send uncommitted response.

View Replies View Related

Servlets :: JPEG Image Upload - Data Input Stream

Jan 25, 2014

Iam trying to upload jpeg image.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

[Code] ....

In servlet the below code

DataInputStream din = new DataInputStream(request.getInputStream());
byte[] data = new byte[0];
byte[] buffer = new byte[50];
int bytesRead;
while ((bytesRead = din.read(buffer)) > 0 ) {

byte[] nData = new byte[data.length + bytesRead];
System.arraycopy(data, 0, nData, 0, data.length);
System.arraycopy(buffer, 0, nData, data.length, bytesRead);
data = newData;
}

What i see is servletinput stream does't have any values.It does't even enter while loop.

View Replies View Related

Unable To Create Audio Stream From Input Stream

Jan 18, 2015

package timerApp;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
import sun.audio.*;
import java.io.*; 
public class timerDriver
{
static int interval;

[Code]...

So I'm trying to make a program that plays an mp3 file after a timer reaches 0, but i keep receiving the error "could not create audio stream from input stream" the audio file is 3.44 MB and 00:03:45 minutes long if that's a problem

View Replies View Related

Program Exits Even When Click No Or X Button On Upper Corner

Mar 31, 2015

Here is the snippet of code that is causing the problem

Java Code:

addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
int confirm = JOptionPane.showOptionDialog(
VendorMachineSimulation.this,
"Are You Sure you want to close this application?",
"Exit Confirmation", JOptionPane.YES_NO_OPTION,

[Code] ....

My question is why does the snippet code at the top works in the class processAction but when I add to the main class that extends JFrame, it exits regardless if I click yes, no or the x button.

View Replies View Related

How To Connect A Stream Via Streamers URL

May 1, 2015

soo, is there a way to (via sockets or something like that) connect to a stream via the streamers url (or just via anything) and then get the actual stream? like the images that keeps updating? so that i can display the images/stream on a jframe?

View Replies View Related

Java I/O - If Stream Contain Nothing Then Close It

Jul 10, 2014

For every stream that we create for java i/o we write at the end in finally block

finally
{
if(is!=null)
{
is.close();
}
}

It works

my question is as per syntax in if (is!=null) this means that if is means stream contain some value then close it(!=null)

then how it in my opnion it should be like (in logical way)

if stream contain nothing then close it

if(is==null)
{
is.close();
}

I am confuse about working this line

View Replies View Related

Byte Stream To String Conversion?

Apr 1, 2014

I am getting byte stream as below. These looks like UTF 8 bytes

3C524F4F543E3C535452494E473E54455354204F4E4C5920535452494E473C2F535452494E473E3C2F524F4F543E

I want java code which will convert above bytes to string as shown below

<ROOT><STRING>TEST ONLY STRING</STRING></ROOT>

View Replies View Related

Possible To Declare Two Data Input Stream?

Aug 3, 2014

I mean i need to access to two txt file at the same time so i did this in method:

DataInputStream din= new DataInputStream(FileInputStream("vip.txt"));

DataInputStream din2= new DataInputStream(FileInputStream("corporate.txt"));

But there are errors when i compile and they pointing to these two lines.

View Replies View Related

Stream To Collection - Saving Results

Mar 25, 2014

I have the following

Java Code: list.stream().sorted((s, s1) -> s.getName().compareTo(s1.getName())).distinct(); mh_sh_highlight_all('java');

I want to save the results to a collection.

I saw an video tutorial on these by Oracle learning library and they mentioned an into(collection) method but I looked at the api and there isn't one.

How can I do it?

View Replies View Related

I/O / Streams :: Invalid Stream Header

Apr 12, 2004

My code runs correctly when i run the clients one after another without using threads.I am getting this following error when i run my multi-threaded server. When a server accepts a client connection, ClientHandler is the thread that handles that client.Exception in thread "main"

java.io.StreamCorruptedException: invalid stream header at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:737) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253) at comm.DOMTransfer.<init>(DOMTransfer.java:25) at ClientHandler.<init>(ClientHandler.java:18) at GridInfo.main(GridInfo.java:34)This is where the error occurs:input = new ObjectInputStream(socket.getInputStream());

View Replies View Related

Second XMLEncoder Silently Dies On Shared Stream?

Jul 5, 2014

My adventures with XMLEncoder continue...

I've got a simple main routine that instantiates two structurally identical classes, and attempts to write them both out to System.out with an XMLEncoder:

package xmlencoding;
import java.beans.XMLEncoder;
public class Twice {
public String name;
public static void main(String[] args)

[code]....

I expected Line 16 and Line 24 to both write some XML-formatted output, looking very similar to each other. But here's my output:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.8.0_05" class="java.beans.XMLDecoder">
<object class="xmlencoding.Twice$C1" id="Twice$C10">
<void class="xmlencoding.Twice$C1" method="getField">
<string>him</string>

[Code] ....

Now, if I change Line 24 so that the second call to writeObject is to a different stream("23. XMLEncoder e2 = new XMLEncoder(System.err);"), I do get both outputs:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.8.0_05" class="java.beans.XMLDecoder">
<object class="xmlencoding.Twice$C1" id="Twice$C10">
<void class="xmlencoding.Twice$C1" method="getField">
<string>him</string>

[code]....

So, I am inferring that this means two XMLEncoder objects can't both hold references to the same OutputStream, even if the first object is closed before the second is created. In actual practice, I guess I can live with that, since I wouldn't write the XML-encoded version of two objects to the same stream (I'd get the header twice in the same file, and I believe that's a no-no). But I am surprised that this doesn't generate some kind of exception, either when the second XMLEncoder is constructed, or when its writeObject method is called. But, it just silently dies.

View Replies View Related

VLCJ Video Stream From Server To Client

Jan 16, 2014

I am try to make an Java application using swing, to play the video from server, client can only view the video.

I am new for using Media Work in Java & using VLCJ too,

I have try by using "vlcj-master".But it showing .dll file missing error on native method..,

View Replies View Related

First Character Is Missing While Reading Input Stream

Jul 10, 2014

This is my code

// TODO Auto-generated method stub
File file=new File("D:/input.txt");
java.io.FileInputStream is=new java.io.FileInputStream(file);
int a=is.read();
try {
while((a=is.read())!=-1) {
System.out.print((char)a);

[Code] .....

My text in file is :my birthday Hello World

But in out i see only:y birthday Hello World

Why is first character is missing here?

View Replies View Related

How To Get Stream Of Data From DVR And Control CCTV Camera

Jul 26, 2014

I am going to to develop an app for my final year project. basically the app is to show live video streaming on android phone from remote CCTV . The project is just in design phase i know the networking part i.e static ip for dvr etc but i dnt know how to get stream of data from dvr and how to control the CCTV camera i.e camera movement....

View Replies View Related

Two Options To Stop Do While Loop?

Oct 11, 2014

In the code that I am currently trying to do, I want to make it so that the program loops until the randomly generated number is 1, to a maximum of 4 loops.I have figured out how to make it stop at a randomly generated 1, but I can't quite figure out how to make it stop at four loops if it doesn't reach the 1 before the maximum number of loops.

View Replies View Related

Swing/AWT/SWT :: Continuous Audio Data Stream Not Working

Oct 15, 2014

I am trying to make my audio loop and i tried the code below

public void audioloop() {
AudioPlayer MGP = AudioPlayer.player;
AudioStream BGM;
AudioData MD;
ContinuousAudioDataStream loop = null;
try {

[Code] ....

But is not working. I was thinking may be API is not work with java 7 because i got the following warning (AudioStream is internal proprietary API and may be removed in a future release);

View Replies View Related

Getting Class Cast Exception While Using Object Input Stream

Jun 5, 2014

I'm developing an application to track the status of a production flow-line and have hit a bit of a snag. When attempting to read saved data I run into this:

Exception in thread "main" java.lang.ClassCastException: flowline.End_Of_File cannot be cast to flowline.Operation
at flowline.Station.checkLoadPreviousStationStatus(Station.java:91)
at flowline.Station.main(Station.java:212)
Java Result: 1

I've been reading up on different methods to saving and retrieving data and have decided ObjectInputStream would be the best option.

The save method works fine, I opted to use a EndOfFile class to determine when I've reached the end of the input stream. The problem is, when my loop encounters this object, it doesn't terminate the loop.

public void checkLoadPreviousStationStatus() throws FileNotFoundException, IOException,
ClassNotFoundException, EOFException, TempArrayOutOfBoundsException{
Object loadOpn = null;
End_Of_File eof = new End_Of_File();
File f = new File(fileName);

[Code] .....

The Operation cast is a cast to the objects my LinkedList contains. The highlighted line is where the exception occurs.

View Replies View Related

Second Packet Read From Input Stream Has Incomplete Data

May 8, 2015

I a simple server that receives bytes using TCP and then saves them to a file stream.Through many tests I have seen that the first packet received is always just the filename with no other data. The second packet received only has one byte and it is the first letter of the input text file. After this all packets are sent correctly, but I can't seem to figure out what is messing up the second packet. It also appears that the last packet is written twice.

Here is an example Input/Output: [URL] .....

InputStream in = clntSock.getInputStream(); //server's input stream - gets data from the client
OutputStream out = clntSock.getOutputStream(); //server's output stream - server sends data to the client
byte[] byteBuffer = new byte[BUFSIZE];
int count = in.read(byteBuffer, 0, BUFSIZE);
String firstRead = new String(byteBuffer, 0, count);

[Code] ....

Another peculiarity to me is that the second to last packet is always just "-" and then the last packet has the remainder of the magic string which terminates the file output stream.

I am aware that it is not safe to make the assumption that the file name will be sent in one go before the loop, but I wil fix that later. I am not concerned about it at all now. THe problem si that the loop should account for any amount read in, but for some reason the first packet always contains one letter, and the second packet picks up around 16000 bytes later for some reason. Why would this be?I can't edit my above post so here is the code with code tags.

InputStream in = clntSock.getInputStream(); //server's input stream - gets data from the client
OutputStream out = clntSock.getOutputStream(); //server's output stream - server sends data to the client
byte[] byteBuffer = new byte[BUFSIZE];
int count = in.read(byteBuffer, 0, BUFSIZE);
String firstRead = new String(byteBuffer, 0, count);

[Code] ....

View Replies View Related

Java Library Function That Searches Stream Of Tcp Packets

Apr 28, 2014

i need a java library function that searches the stream of tcp packets coming to my computer from a particular ip address, so i can perform regular expressions on the contents of those packets.

View Replies View Related

How To Stop Program When Entering Certain Number

Dec 2, 2014

how many integers the user wants to use. The user will enter for example a 4. The user inputs a 2, 4, 6, and 10. So then we get our outputs...Then the code will ask if you want to run this program again. My question is, if the user inputs a -1 for example 2, 4, 6, -1....the code will not continue. I wanted to use a while loop, such as while (scores != -1) but it doesn't work.

Enter the amount of integers you want to use4
Intenger # 1 2
Intenger # 2 4
Intenger # 3 6
Intenger # 4 10
You entered 2.0 4.0 6.0 10.0
Average = 5.5
Variance = 8.75
Standard Deviation = 2.96
Do you have another set of numbers?

[code]....

View Replies View Related

Swing/AWT/SWT :: Application Just Stop Itself During Execution

May 18, 2014

I made a check4 application with Java.It correctly works but sometimes the application just stop itself during the execution.I never had a problem like this. The application just stop itself and i can't even quit using the closing button..

View Replies View Related

How To Stop Infinite Loop Programmatically

Mar 24, 2015

I am developing application called java compiler... It takes java program as input and compiles and run it, gives output. but if input program has infinite loop then how can identify and stop process execution.

View Replies View Related

Play / Stop And Loop Three Different Songs

May 13, 2014

I am making a project that should play, stop, and loop three different songs (not at the same time). I am calling this SoundPlayer class from my main class:

import javax.sound.sampled.*;
import java.util.*;
public class SoundPlayer {
List<AudioInputStream> songs = new ArrayList<AudioInputStream>();
int currentSong, currentPlayType;

[Code] ....

When my class calls setPlayType(2), which should make it play, I get the following runtime error:

java.lang.NullPointerException
at SoundPlayer.playSong(SoundPlayer.java:32)
at SoundPlayer.setPlayType(SoundPlayer.java:64)
at MainPanel$AListener.actionPerformed(MainPanel.java:60)
(...)

Line 32 is if(clip.isOpen()), but I'm pretty sure I instantiated clip properly in the constructor.

View Replies View Related

Get Code To Stop Overwriting The Output?

May 1, 2014

What I mean is, I have this set and it is supposed to take out all the duplicates. If I enter aaabbbcccd the output should be abcd, but instead my code just outputs the last word, or in this case letter entered.

import java.util.*;
public class setdemo
{
public static void main(String[] args)

[Code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved