Click here to Skip to main content
15,887,676 members
Home / Discussions / Java
   

Java

 
AnswerRe: Server Socket is closed on client closed Pin
Richard MacCutchan20-May-13 22:57
mveRichard MacCutchan20-May-13 22:57 
GeneralRe: Server Socket is closed on client closed Pin
Sachin k Rajput 20-May-13 23:02
Sachin k Rajput 20-May-13 23:02 
GeneralRe: Server Socket is closed on client closed Pin
Richard MacCutchan21-May-13 2:34
mveRichard MacCutchan21-May-13 2:34 
GeneralRe: Server Socket is closed on client closed Pin
MarlBermudoNights3-Jul-13 22:37
professionalMarlBermudoNights3-Jul-13 22:37 
AnswerRe: Server Socket is closed on client closed Pin
jschell21-May-13 7:57
jschell21-May-13 7:57 
GeneralRe: Server Socket is closed on client closed Pin
Sachin k Rajput 21-May-13 17:29
Sachin k Rajput 21-May-13 17:29 
GeneralRe: Server Socket is closed on client closed Pin
Richard MacCutchan21-May-13 21:15
mveRichard MacCutchan21-May-13 21:15 
AnswerRe: Server Socket is closed on client closed Pin
gongxufan@china.java22-May-13 1:30
gongxufan@china.java22-May-13 1:30 
I think you should make a loop in your server code.
Just like the test code below.
Java
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) {
        // TODO Auto-generated constructor stub
        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

Smile | :) Try it !
GeneralRe: Server Socket is closed on client closed Pin
Sachin k Rajput 22-May-13 2:10
Sachin k Rajput 22-May-13 2:10 
Questiontomcat and eclipse Pin
prithaa20-May-13 0:50
prithaa20-May-13 0:50 
AnswerRe: tomcat and eclipse Pin
Prasad Khandekar21-May-13 4:31
professionalPrasad Khandekar21-May-13 4:31 
QuestionWindows Media Player Pin
MAYNUL18-May-13 10:28
MAYNUL18-May-13 10:28 
AnswerRe: Windows Media Player Pin
Richard MacCutchan18-May-13 21:20
mveRichard MacCutchan18-May-13 21:20 
Questionanalysing utterances Pin
HopePerson14-May-13 18:09
HopePerson14-May-13 18:09 
QuestionRe: analysing utterances Pin
Richard MacCutchan14-May-13 21:26
mveRichard MacCutchan14-May-13 21:26 
QuestionJList is returning null value Pin
Sachin k Rajput 13-May-13 20:15
Sachin k Rajput 13-May-13 20:15 
AnswerRe: JList is returning null value Pin
TorstenH.13-May-13 21:36
TorstenH.13-May-13 21:36 
GeneralRe: JList is returning null value Pin
Sachin k Rajput 13-May-13 21:44
Sachin k Rajput 13-May-13 21:44 
GeneralRe: JList is returning null value Pin
Shubhashish_Mandal14-May-13 3:24
professionalShubhashish_Mandal14-May-13 3:24 
GeneralRe: JList is returning null value Pin
Sachin k Rajput 14-May-13 18:09
Sachin k Rajput 14-May-13 18:09 
GeneralRe: JList is returning null value Pin
TorstenH.15-May-13 20:26
TorstenH.15-May-13 20:26 
QuestionPerform -> key press Event on GUI programmatically Pin
Sachin k Rajput 12-May-13 20:10
Sachin k Rajput 12-May-13 20:10 
AnswerRe: Perform -> key press Event on GUI programmatically Pin
Richard MacCutchan12-May-13 21:20
mveRichard MacCutchan12-May-13 21:20 
GeneralRe: Perform -> key press Event on GUI programmatically Pin
TorstenH.12-May-13 22:40
TorstenH.12-May-13 22:40 
GeneralRe: Perform -> key press Event on GUI programmatically Pin
Richard MacCutchan12-May-13 23:07
mveRichard MacCutchan12-May-13 23:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.