• Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket Programming  RSS feed

 
pollai mandala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends,
I came with a problem related to the messenger type application.
My problem is explained here:
1) for all the active users that are connected for chatting i am storing the (server side)sockect-output streams in a hash table.After some time gap they seem to be disabled.they are not responding when we try to print some thing into that stream.At clint's port while reading readLine() i am getting null.
2)if suddenly the client application aborted from
execution, i am not able to knowthat information.
The server doesn't know that , so the user-info,output stream is not removed from that hashtable which causes the server to treat that user as active.so if there is any other user who
tries to send message to this aborted-user the messages are printed through the invalid output stream.But those messages should be stored in the database like offline messages actually.
so i need to be informed if any user exited abnormally.
any help is appreciated.

 
Pawel Veselov
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
about 1)
The TCP times out after a certain amount of time, this is protocol specific feature. So, if you want this not to happen, you need to send/receive keep-alive packets.
about 2)
I thought, that sending data to a dead socket will cause an exception... Anyway there definitely will happen something, like the result of the write() will be 0, or smth, so this is the good reason to start treating user as dead. Or ask user agent to send back a confirmation that the message was accepted on the other side, then if server doesn't receive a ack within a timeout, user can be counted dead. In case of using the keepalives this can be found out even when user is idle.

------------------
With best of best regards, Pawel S. Veselov ( aka Black Angel )
 
pollai mandala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for a quickly response Pawel S. Veselov,
what u have said is correct.I have already applied this.But
we can simply realize that this will cause peformance bottlenecks.If we implemebnt the send/receive packet mechanism
means its like we are about to reimplment TCP/IP for a little.
i'll be waiting for ur reply,
with Best Regards..
 
pollai mandala
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Pawel S. Veselov & other friends,
I got a solution for my problem.Till now i have been using BufferedReader for listenting for the incoming messages at clint
side.That's why all the messages are being buffered somewhere.(i guess..).So the failure of message communication is not known at the time of sending to the dead sockets.
Now i am using ObjectOutputStream and ObjectInputStream for message communication between the sockets.Presently there is
no problem found.Whenever aborted user socket found, iam getting
exception which lets me handle the problem.
I want to continue discussion on this issue with all of U,any way.
thanks
 
alexander Petrovich
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I described some mechanism for checking of network connection and keeping it alive in reply to Rick in thread "Thread on Socket?" It doesn't cause performance bottleneck and network flood... Absolutelly!
And did you try to socket.setSoTimeout(0). "0" for unlimited connection?
alex from JavaFaq http://www.erudite-center.com/java
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!