• Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing MVC and network  RSS feed

 
biraji gafiff
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone, i working on a simple application that connect to the server, wait the confirmation, enter a value and send. I am stuck on that confirmation from the server, it must wait the confirmation to send the data. How could i do that? I was looking for examples using listeners but i could not find it.

Thanks in advance.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of server? Is the "connect"ing, "confirmation" and "send"ing an existing program/protocol, or is it something you're making yourself?

Also - all that Swing deals with is GUI components. Swing listeners are for different types of GUI actions - not network messages.
[ November 20, 2006: Message edited by: Nathan Pruett ]
 
biraji gafiff
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using sockets and streams. I�ve created some codes to identify the messages from the server, i don�t know if it is correct but it works. Any ideias?
Thanks.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pretty much there are only 2 ways of doing something like a "listener" with socket calls - polling or callbacks.

Polling means that the client keeps calling the server until it receives what it wants... there can be multiple approaches to this - but basically it boils down to something like this:

Client - "Give me the data."
Server - "Sorry, ask again."
Client - "Give me the data."
Server - "Sorry, ask again."
Client - "Give me the data."
Server - "Sorry, ask again."
Client - "Give me the data."
Server - "Sorry, ask again."
Client - "Give me the data."
Server - "Sorry, ask again."
Client - "Give me the data."
Server - "Here you go."
Client - "FINALLY!" :roll:

Callbacks mean that the client gives the server a way to contact it, and the server then "calls back" when it's ready with the data. This basically reverses the roles of client and server for this call. Callback are much less network intensive, but require more setup, and might not be possible under all circumstances (i.e. - over the internet, where the client and server might be behind NAT routers or firewalls that would prevent setting up ports clients can listen on on-the-fly.) Callbacks would play out more like this:

Client: "When the data's ready, call me on port 5099."
Server: "OK"
[Server goes to work on producing data.]
[Client does other stuff while waiting.]
[Server finishes producing data.]
[Server calls client on port 5099.]
Server: "Here's that data you wanted."
Client: "That sure took you long enough." :roll:
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this has strayed out of the topic of the forum, I'm moving it to a more appropriate one - Sockets and Internet Protocols.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!