• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

tcp socket communication-persistence connection

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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 connection.so that i can able to send and receive data without opening the connection everytime
Kindly post me regarding this query
Regards
sangeeth
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A persistent connection to what? A web server? Web servers don't work that way.
 
pp sangeeth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Client
*********
//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
theReader.close();
theWriter.close();
soc.close();
***** end of the part of the code *****
now i want to split the above stpes into separate methods
for example,
open
close
send
receive
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,
Sangeeth

 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ,
Sangeeth
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic