|
Well, you need to catch it first.
Use the best guess
|
|
|
|
|
try{
}catch(SocketException e){
Sytem.err.println(e);
}
|
|
|
|
|
Indian Coder1989 wrote: I want to create a server socket(TCP) in which I want that server shouldn't be
closed if client is closed.
As stated that of course is illogical. Once the client terminates, regardless of how it happened, the server side connection can no longer be used.
|
|
|
|
|
OfCourse the server will be disconnected and connection will be closed but program shouldn't be crashed.
Isn't it possible that next time when client will again connected there will not be a need to start the server again(means server shouldn't be crashed)?
|
|
|
|
|
I already told you twice what to do: catch the exception and dispose it, so the server continues to listen in an idle state. How do you think the rest of the internet works?
Use the best guess
|
|
|
|
|
I think you should make a loop in your server code.
Just like the test code below.
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class Test {
public static void main(String[] args) throws Exception {
ServerSocket server = new ServerSocket(888);
while(true) {
Socket s = server.accept();
Processer p = new Processer(s);
Thread t = new Thread(p);
t.start();
}
}
}
class Processer implements Runnable {
private Socket socket;
public Processer(Socket s) {
this.socket = s;
}
@Override
public void run() {
try {
PrintWriter out=new PrintWriter(socket.getOutputStream(),true);
out.println("HTTP/1.0 200 OK");
out.println("Content-Type:text/html;charset=utf-8");
out.println();
out.println("<h1> web service test sucess!</h1>");
out.close();
} catch(Exception ex) {
ex.printStackTrace();
} finally {
try {
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
To test the result,using http://127.0.0.1:888 in yor brower
Try it !
|
|
|
|
|
Thanks!
This is the thing, I was looking for.
Let me try this in my project.
|
|
|
|
|
Hello,
I have installed tomcat 6 with eclipse but now i want to install tomcat 7 with eclipse . But I keep getting the error
The Apache Tomcat installation at this directory is version 6. A tomcat 7 installation is expected.
Any idea how should i go about it.
Pritha
|
|
|
|
|
Hello Pritha,
You may find this tutorial useful in solving your issue. Also check whether CATALINA_HOME or TOMCAT_HOME environment variables are set and are pointing to wrong directory.
Regards,
Prasad P. Khandekar
Knowledge exists, man only discovers it.
|
|
|
|
|
Hi,
I have to made Windows Media Player. Can anybody suggest me how can I work on it!!
Thanx in advance
May
|
|
|
|
|
|
Hi Guys,
just wanted to know how I can build lexical and syntacitc analysis using Jlex in eclipse for generating texts !!!
any one can help me please I am stuck ??!!
Thanks in advance
|
|
|
|
|
HopePerson wrote: I am stuck With what? You need to give specific details of your problem if you want some useful suggestions.
Use the best guess
|
|
|
|
|
I'm showing or selecting images from a list.
My code for listselectionlistener is:
listener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
index = imageList.getSelectedIndex();
imageList.setSelectedIndex(index);
o = imageList.getSelectedValue();
if (o instanceof BufferedImage) {
imageView.setIcon(new ImageIcon((BufferedImage)o));
}
}
};
imageList.addListSelectionListener(listener);
to get next item in JList (imageList) I'm coding like this:
public void nextimage()
{
index ++;
imageList.addListSelectionListener(listener);
imageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
imageList.setSelectedIndex(index); -----here is error: Null Pointer Exception
}
I initialize index as int index=0;
Program in starting returning right value but after 4 or 5 images it's not working.
How can I change the Item in this list?
Please suggest your opinions.
|
|
|
|
|
You need to check if the JList does contain so much values.
You're not coding safe. You need to take more care.
You can never expect a value to be there as you need it - always check if the value is valid before you use it!
|
|
|
|
|
Thanks for your quick reply.
Will you be more specific on checking the value?
As I'm selecting the value from Jlist that is showing thumbnails.
I'm not getting the exact way for selecting next item.
|
|
|
|
|
"TorstenH" want to say you that you have to check the "index" value before using it to set the selected item. You should check "index" value whether it is in the range of your image list size.
Regards
Shubhashish
|
|
|
|
|
Well I did this.
The only problem was SwingUtlities.InvokeLater().
|
|
|
|
|
That's a function, not a problem.
The problem would be that you tried to update the GUI while you where using it.
SwingUtilities.InvokeLater()[^] would cause the Thread to wait and update the GUI when possible.
|
|
|
|
|
How can I perform arrow key event for a GUI in my Java Program?
Thanks!
|
|
|
|
|
|
|
Thanks, all I did was go to the 'K' section in the documentation index.
Use the best guess
|
|
|
|
|
Thanks for your suggestions..
My problem is I want to change the item in a Jlist Programmatically.
That's why I wanted to use this but Robot(AWT key Press Event)not working.
My code is:
listener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Object o = imageList.getSelectedValue();
if (o instanceof BufferedImage) {
imageView.setIcon(new ImageIcon((BufferedImage)o));
}
}
}
imageList.addListSelectionListener(listener);
Well the code is working fine but I want to change the next image using a button or something else
How can I do this?
Please help me in this?
|
|
|
|
|
Sorry, I don't understand the problem. Maybe you need to look at some of the GUI tutorials[^].
Use the best guess
|
|
|
|