• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

socket programming : connect server to client

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I am trying to develop client/server application using nonblocking nio, i have found example in the book "TCP/IP Sockets in Java Practical Guide for Programmers
Second Edition Kenneth L. Calvert - University of Kentucky Michael J. Donahoo - Baylor University "


the code as the following:
TCPEchoClient.java




TCPServerSelector.java



TCPProtocol.java



EchoSelectorProtocol.java




the example working fine , as the following

1)I have started running the server application "TCPServerSelector.java"
2)I have run 2 clients using the application "TCPEchoClient.java"

as i know that the The client initiates communication with a server
but sometimes want to send a message from server to a particular client or we want to check whether xyz client is one of active client connected to the server or not
so how i do achieve that in the above examples
 
anitha meena
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All , Any reply ................
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taking a quick look at the client, it seems that the client sends something to the server, receives a response, and then shuts down. If the server is supposed to send something to the client, then that implies that the client needs to be running - which it won't under the current setup. So for starters, you need to set up the client to keep running, and you need to change it so that it can receive multiple message from the server. That means it must be able to recognize if a server message is done, and when the next one starts. And, obviously, the server needs to be able to send messages at its discretion - which it currently can't, since it only responds to client requests.
 
anitha meena
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot i have fixed the issue but my question now is that


if the client establishes socket connection to the server and the server replies to this client . after that the client stays idle for long time let say 2 hours but the socket connection still alive , is it possible for the server now to send something to the client ( i mean the server will send request and the reply will from the client) ......
 
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the connection is still active then yes, it should be possible to send messages to the client. If the client is not reading from its input stream that data will not be processed though, so make sure the client keeps reading data from the server.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Dear:


My method is to send XX to the client whick you want to send msg to and you don't know if it is alive.

if execute the send XX method ,if the client is inalive, the server must catch a excepthion.

Notice: XX is your protocol like a Heartbeat message between server and client.

 
A timing clock, fuse wire, high explosives and a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic