• 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

Writing My Own Protocol

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey everyone,

Ok so what im trying to do is refactor a recent project into a client/server architecture. Here's the version i want to refactor.

festivalplanner.net

The server will connect to the database and serve the festival info to the clients connected. I know how to setup sockets and setup a basic client and a basic server after reading some simple tutorials.

Here are two scenarios of what a client should be able to do.

1. The client makes a request to the server to list all festivals.
2. The client makes a request to see events for a certain festival.

How do i do this on the server and the client

Client Code

try {
Socket s = new Socket("localhost", 4892);

//input
InputStreamReader streamReader = new InputStreamReader(s.getInputStream());
reader = new BufferedReader(streamReader);

//output
writer = new PrintWriter(s.getOutputStream());


System.out.println("Connection established to Server");

}

Do i do something like writer.write("Get Festival List"); for scenario 1.


Anybody have any experience with stuff like this that could point me in the right direction?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Socket-level protocols are a pain to write and fall into all sorts of platform-dependent traps. I recommend you use Remote Method Invocation. It basically gives you an object interface to the network so you don't have to deal with the details of cramming stuff into a socket and can concentrate on the object-level design problems
 
Rob Grubb
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are there any downsides to rmi? Would i be better off using something like glassfish?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Grubb wrote:are there any downsides to rmi?



Sure. All remote methods have to throw a RemoteException so it is not as unobtrusive as it sounds. I've seen people complain about performance, but I haven't seen their code or traffic numbers.

Rob Grubb wrote:Would i be better off using something like glassfish?



Glassfish is a servlet container. You'd have to use HTTP, which isn't a great choice for a strict client/server architecture because it is stateless. It's great if you want to make an application that someone will use a web browser to access or you want to leverage one of the great web app frameworks (Struts, Spring, Stripes), but it will have an awful lot of overhead.
 
Rob Grubb
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sweet thanks for the insight joe, think ill go with RMI.
 
reply
    Bookmark Topic Watch Topic
  • New Topic