Title:
Thanks for your response,
But the reason should be something different. You are true, accept is
blocking waiter.
If I put it into while loop, my application hosts more than one connection.
On the otherhand one connection is enough for my application.
Problem is that: application couldn't aware connection request if I try to
connect in servlet.There could be different reasons, I'll search.
Regards,
Fusun


----- Original Message -----
From: "Richard Yee" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, September 24, 2001 9:15 AM
Subject: Re: Socket connection is servlet


> Fusun,
> The application should always be listening for connections.
> Your serverSocket.accept() method call should be in a while loop like
this:
>
> // server infinite loop
> import java.net.*;
> import java.io.*;
>
> public class tcpServer
>
> public static void main(String args[])
>
> int port;
> ServerSocket server_socket;
> BufferedReader input;
>
> try
> port = Integer.parseInt(args[0]);
>
> catch (Exception e)
> System.out.println("port = 1500 (default)");
> port = 1500;
>
>
> try
>
> server_socket = new ServerSocket(port);
> System.out.println("Server waiting for client on port " +
> server_socket.getLocalPort());
>
> while(true)
> Socket socket = server_socket.accept();
> System.out.println("New connection accepted " +
> socket.getInetAddress() +
> ":" + socket.getPort());
> input = new BufferedReader(new
> InputStreamReader(socket.getInputStream()));
> // print received data
> try
> while(true)
> String message = input.readLine();
> if (message==null) break;
> System.out.println(message);
>
>
> catch (IOException e)
> System.out.println(e);
>
>
> // connection closed by client
> try
> socket.close();
> System.out.println("Connection closed by client");
>
> catch (IOException e)
> System.out.println(e);
>
>
>
>
> The accept method will block until a connection is made to the server
> socket port. Once a socket is established, you need to do whatever you
> need to do to process the data going into or out of the socket by getting
> the input or output streams of the socket and reading or writing from it.

This message was posted using eunum
To interact with a real-time, threaded interface to this e-mail list, clickthe link below:

[EMAIL PROTECTED]

___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to