This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Applets and the fly likes tcp socket communication-persistence connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "tcp socket communication-persistence connection" Watch "tcp socket communication-persistence connection" New topic

tcp socket communication-persistence connection

pp sangeeth

Joined: Aug 04, 2001
Posts: 8
i want to open a connection when i log into my application and the connection needs to be persistant till i
log out or until i forced to close the that i can able to send and receive data without opening the connection everytime
Kindly post me regarding this query
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964

A persistent connection to what? A web server? Web servers don't work that way.

Customer surveys are for companies who didn't pay proper attention to begin with.
pp sangeeth

Joined: Aug 04, 2001
Posts: 8
Hi Tim Holloway ,
Thanks for your reply ...
No , i donot want to have a connection with webserver.
i want to make a connection using socket(tcp /ip communication).
Please see the following for the client side code
//open the connection
InetAddress hostAddr = InetAddress.getByName(IPADDRESS);
int hostPort = PORT;
Socket soc = new Socket(hostAddr,hostPort);
//Send value to server
PrintWriter theWriter = new PrintWriter(soc.getOutputStream(),true);
theWriter.println("Hi from client ");
//receive the data from the server
String input = "NoValue";
BufferedReader theReader = new BufferedReader(new InputStreamReader(soc.getInputStream()));
while((input = theReader.readLine()) != null)
System.out.println("SERVER REPLIED : " + input + "\n");
//close the socket ,I/O stream
***** end of the part of the code *****
now i want to split the above stpes into separate methods
for example,
so from another class ie at the start point- may be login time) of the applicaion i can call open method to establish the connection and i can call send and receive method for many time s to send and receive the data and in the end point(may be loged out ) of the application i can call close method to close the socket.
Hope now you can have an idea about what i am asking....
i want to save the time for open and close the socket for each and every request and response.
Thanks & Regards,

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964

OK, but you never did say what kind of server you wanted to talk to. Just some app you wrote using sockets?
The sandbox rules apply to socket I/O just as they do to higher-level network I/O, so bear that in mind. Probably what you want to do is have the applet open the socket, then manage the network connection with threads, so that the applet's UI doesn't get bogged down (depends on what all is supposed to be happening at the time). Excluding the extra security, there's no magic to it. Well, almost none. When people flip around web pages, crash their browsers, etc. that can make it harder to detect when they've "logged out", but that's just something you have to allow for - supply a "disconnect" button and/or log off in the applet's "stop" method.
pp sangeeth

Joined: Aug 04, 2001
Posts: 8
Hi Tim Holloway,
In our application the server side coding are in "c" and the client side is in "java".so all the session handling things will be take care by "c".Our "c" team is working on it so that from java i can able to have one time connection and hope the issue will be solved.
Thanks ,
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964

Interesting. Have you considered CORBA? It might be simpler for what you want.
I do need to make the standard "It probably won't work on the Internet disclaimer" - CORBA tcp/ip ports will probably be blocked by most firewalls.
Of course, the same can be said of most NON-CORBA tcp/ip ports - which is why SOAP is the up-and-coming thing - it runs via the http ports.
I agree. Here's the link:
subject: tcp socket communication-persistence connection
Similar Threads
socket connection
proxool.connect problem
Where to keep system-wide (global) data in JEE application
log setting (
Rolling Tomcat Connector Log