Client-Server office discussion. Need a pattern ?

Hello all,
1. We are new in network programming, so please forgive us for such a dum question.
In our last project we were requested to write a very simple java server which would handle some "Task process" state by recieving commands "start,stop,getStatus".
Although we were able to easily write the code, we had a doubt that created a team discussion.
Were should the socket connection be stablished ?
Some of us stated that the "Constructor" should establish the connection to the socket, as the "Server" can not exists if it is not listening to a port.
Some others stated that a "Run/Start" method should do this.
Obviouly either way works, yet I'm hopping that the Gurus here can help us determine the right answer.
2. I read about MVC pattern but I can't find a link to a well explained "Client-Server" pattern. Does anyone know a good place to find patterns ?
Thanks in advanced for you help !!!
It's great to be part of this community.
Thanks..

Hello all,
1. We are new in network programming, so please
forgive us for such a dum question.
In our last project we were requested to write a very
simple java server which would handle some "Task
process" state by recieving commands
"start,stop,getStatus".
Although we were able to easily write the code, we
had a doubt that created a team discussion.
Were should the socket connection be stablished ?
Some of us stated that the "Constructor" should
establish the connection to the socket, as the
"Server" can not exists if it is not listening to a
port.
Some others stated that a "Run/Start" method should
do this.
Obviouly either way works, yet I'm hopping that the
Gurus here can help us determine the right answer.
Why not use a Servlet? That having been said, if I did want to re-invent the wheel, I would add startListening() and stopListening() methods to the class that manages the ServerSocket. You can always force a JVM exit, but why not at least provide methods for callers that want to end gracefully?
2. I read about MVC pattern but I can't find a link
to a well explained "Client-Server" pattern. Does
anyone know a good place to find patterns ?
Thanks in advanced for you help !!!
It's great to be part of this community.
Thanks..Do a Google search on writing a multi-threaded server. A number of patterns could apply. Client-server is really an architecture, not a pattern. Any number of patterns (or anti-patterns) could actually implement it.
- Saish

Similar Messages

  • Client/server RMI app using Command pattern: return values and exceptions

    I'm developing a client/server java app via RMI. Actually I'm using the cajo framework overtop RMI (any cajo devs/users here?). Anyways, there is a lot of functionality the server needs to expose, all of which is split and encapsulated in manager-type classes that the server has access to. I get the feeling though that bad things will happen to me in my sleep if I just expose instances of the managers, and I really don't like the idea of writing 24682763845 methods that the server needs to individually expose, so instead I'm using the Command pattern (writing 24682763845 individual MyCommand classes is only slightly better). I haven't used the command pattern since school, so maybe I'm missing something, but I'm finding it to be messy. Here's the setup: I've got a public abstract Command which holds information about which user is attempting to execute the command, and when, and lots of public MyCommands extending Command, each with a mandatory execute() method which does the actual dirty work of talking to the model-functionality managers. The server has a command invoker executeCommand(Command cmd) which checks the authenticity of the user prior to executing the command.
    What I'm interested in is return values and exceptions. I'm not sure if these things really fit in with a true command pattern in general, but it sure would be nice to have return values and exceptions, even if only for the sake of error detection.
    First, return values. I'd like each Command to return a result, even if it's just boolean true if nothing went wrong, so in my Command class I have a private Object result with a protected setter, public getter. The idea is, in the execute() method, after doing what needs to be done, setResult(someResult) is called. The invoker on the server, after running acommand.execute() eventually returns acommand.getResult(), which of course is casted by the client into whatever it should be. I don't see a way to do this using generics though, because I don't see a way to have the invoker's return value as anything other than Object. Suggestions? All this means is, if the client were sending a GetUserCommand cmd I'd have to cast like User user = (User)server.executeCommand(cmd), or sending an AssignWidgetToGroup cmd I'd have to cast like Boolean result = (Boolean)server.executeCommand(cmd). I guess that's not too bad, but can this be done better?
    Second, exceptions. I can have the Command's execute() method throw Exception, and the server's invoker method can in turn throw that Exception. Problem is, with a try/catch on the client side, using RMI (or is this just a product of cajo?) ensures that any exception thrown by a remote method will come back as a java.lang.reflect.InvocationTargetException. So for example, if in MyCommand.execute() I throw new MySpecialException, the server's command invoker method will in turn throw the same exception, however the try/catch on the client side will catch InvocationTargetException e. If I do e.getCause().printStackTrace(), THERE be my precious MySpecialException. But how do I catch it? Can it be caught? Nested try/catch won't work, because I can't re-throw the cause of the original exception. For now, instead of throwing exceptions the server is simply returning null if things don't go as planned, meaning on the client side I would do something like if ((result = server.executeCommand(cmd)) == null) { /* deal with it */ } else { /* process result, continue normally */ }.
    So using the command pattern, although doing neat things for me like centralizing access to the server via one command-invoking method which avoids exposing a billion others, and making it easy to log who's running what and when, causes me null-checks, casting, and no obvious way of error-catching. I'd be grateful if anyone can share their thoughts/experiences on what I'm trying to do. I'll post some of my code tomorrow to give things more tangible perspective.

    First of all, thanks for taking the time to read, I know it's long.
    Secondly, pardon me, but I don't see how you've understood that I wasn't going to or didn't want to use exceptions, considering half my post is regarding how I can use exceptions in my situation. My love for exception handling transcends time and space, I assure you, that's why I made this thread.
    Also, you've essentially told me "use exceptions", "use exceptions", and "you can't really use exceptions". Having a nested try/catch anytime I want to catch the real exception does indeed sound terribly weak. Just so I'm on the same page though, how can I catch an exception, and throw the cause?
    try {
    catch (Exception e) {
         Throwable t = e.getCause();
         // now what?
    }Actually, nested try/catches everywhere is not happening, which means I'm probably going to ditch cajo unless there's some way to really throw the proper exception. I must say however that cajo has done everything I've needed up until now.
    Anyways, what I'd like to know is...what's really The Right Way (tm) of putting together this kind of client/server app? I've been thinking that perhaps RMI is not the way to go, and I'm wondering if I should be looking into more of a cross-language RPC solution. I definitely do want to neatly decouple the client from server, and the command pattern did seem to do that, but maybe it's not the best solution.
    Thanks again for your response, ejp, and as always any comments and/or suggestions would be greatly appreciated.

  • Are there any Client/Server Application (using sockets) design patterns?

    Hi,
    The title of the post nearly says it all. I am searching for different design patterns related with the development of a client/server application. I understand that there must be any different ways on how a client/server application can be developed.
    Regards,
    Sim085
    Disclaimer:
    When I enter in the Socket forum on this site I recieve this message "Thank you for any participation in this forum. Due to a lack of relevant activity, we have decided to archive this forum on June 16, 2006. For future posts on this topic, we suggest you use the Networking forum" and I am not allowed to create a new post! However I can see posts done yesterday! All i did is add the forum in 'my forums'. Does this happen to you people as well?

    Hi Sim085...How are you?
    So look this:
    http://forum.java.sun.com/thread.jspa?threadID=5148926&tstart=75
    I don�t know if is what you want...but I hope in this^^
    Ok man...If you have one example for help you is better.
    [ ]

  • Client/Server between iPhones

    Hi all,
    I have to develop a networking component for multiplayer games on iPhone. I wondered about the possibility to build a client/server achitecture over bluetooth between two or more iPhones, and if it was possible using CFSocket, CFNetwork classes ? Or are there other useful classes ?
    Thank you.

    To enable cross release client/server operation you need to add the line
    -insecure-backwards-compat
    to the ttendaemon.options file located in <tt_install_dir>/info on the system that hosts the datastores that you wish to connect to. For this to take effect you must restart the main daemon so you will need to shutdown all the datastores before doing this!
    This is documented in the TimesTen Installation Guide and the Timesten operations Guide.
    Regards,
    Chris

  • Client/Server connection between unix machines

    Hi,
    I have a problem about connectivity.
    When I try connect to a dsn in a server from a machine with client TimesTen software installed.
    Details:
    CLIENT1: TimesTen Release 7.0.5.0.0 (32 bit Solaris/x86) (tt705) 2008-04-04T00:06:33Z
    SERVER1: TimesTen Release 7.0.3.0.0 (32 bit Solaris) (tt703:17000) 2007-09-12T05:45:43Z
    SERVER2: TimesTen Release 7.0.3.1.0 (32 bit Solaris) (tt703:17000) 2007-10-30T22:52:42Z
    SERVER3: TimesTen Release 7.0.3.1.0 (32 bit Solaris) (smpcluster:15000) 2007-10-30T22:52:42Z
    connections CLIENT1 --> SERVER1 ==> OK
    connections CLIENT1 --> SERVER2 ==> KO
    connections CLIENT1 --> SERVER3 ==> KO
    user@CLIENT1 > ttIsqlcs ngincz_prod_s3scp03
    Copyright (c) 1996-2008, Oracle. All rights reserved.
    Type ? or "help" for help, type "exit" to quit ttIsql.
    All commands must end with a semicolon character.
    connect "DSN=ngincz_prod_s3scp03";
    S1000: Protocol mismatch; client protocol: 32, server protocol: 32
    S1010: Function sequence error
    The command failed.
    Done.
    In error log file server we can see these messages:
    11:44:50.42 Err : SRV: 14749: EventID=37| Client version 32 is not supported, the current server version is 31. Contact TimesTen support for instructions on how to download new versions of TimesTen Client/Server
    11:44:50.42 Err : SRV: 14749: EventID=68| Failed to read request from client. Closing connection without reply.
    Any idea about cause/solution ??

    To enable cross release client/server operation you need to add the line
    -insecure-backwards-compat
    to the ttendaemon.options file located in <tt_install_dir>/info on the system that hosts the datastores that you wish to connect to. For this to take effect you must restart the main daemon so you will need to shutdown all the datastores before doing this!
    This is documented in the TimesTen Installation Guide and the Timesten operations Guide.
    Regards,
    Chris

  • Any handy client/server patterns?

    Hi!
    I'm building a client/server application that communicate using Serializable Objects.
    For example, the application need to do request/response, waiting for the result.
    This could be a request to store items, or to retreive a list of items.
    The Server need to send messages to applications which will handle them right away, as they arrive.
    This could be as simple as a displaying a message to the user of the application, or a message interpreted by the application itself.
    I'm thinking of something "event driven", Publish/subscribe looking implementation.
    One application should be able to respond to events originated from another application.
    One of the problems is that the application cannot receive messages from the server while it is waiting for the result of a request/response.
    Do you know of any patterns that cover this or somehting similar?
    I can think of either some multiplexing scheme or separate threads/ network connections.
    But as allways, its easier to reuse something allready working :)
    - Flexibility over performance is prefered
    - There will never (ehum) be more than 10 active users at a time
    - The request/response messages scheme need not be very fast
    - The "small" messages (events) must be handled almost instantly (one user sees changes made by another user)
    - The size of the messages is small. Either a few lines of code (events, commands), or a dozen records (query results)
    - The number of messages is small
    / Ronnie

    The Model-View-Controller design pattern solves these problems by decoupling data access, business logic, and data presentation and user interaction.
    A

  • I Need Information about  Open Source Java Client/Server Instant Messaging

    I need your valuable help and collaboration with the following issue:
    I need to know where can find a robust Open Source Java Instant Messaging Client/Server Application.
    I thank in advance for their valuable time. And for the attention and the collaboration lent to me.

    I was going to mention that right off, but since the OP is clearly unaware of the search engines on the Web, I thought I'd give him a hand. Jabber works pretty good - I tried it a while back and some of the clients were ... quirky.

  • Need help in desigining Client/Server Application using Java

    Hi,
    I am new to Java and no sooner that I started studing it I have been given a project - client server java Application that allows a user to do a property search based on critiras (eg location, price) and display the results. I am stuck because I don't know where I need to start. Have to use IDE (Netbeans or Eclipse) but not sure about dev frameworks.
    Can someone give me an outline of what I should do / where I should start? What will be the best solution?
    Thanks in adance

    http://java.sun.com/docs/books/tutorial/networking/index.html
    That's Sun's networking tutorial series. Live it, learn it, love it. You'll need to decide if you want to use connected sockets or datagrams. You'll need details like, can multiple clients connect simultaneously?
    The tutorials are the first step though.

  • Need HELP in JAVA ( client /server application )

    hi there ,
    I need the following codes in java for my client/server application . which i can use to perform certain function on another computer on LAN. This is part of my semester project . I would really appreciate if any one can help me
    ->Open/close the CD-ROM once or in intervals (specified in seconds).
    ->Swap mouse buttons the right mouse button gets the left mouse button's functions and vice versa.
    ->Start optional application.
    ->Play optional sound-file.
    ->Point the mouse to optional coordinates.
    ->Shutdown the system, logoff the user etc.
    ->Mouse can be controlled on the target computer with remote mouse.
    ->Keys (letters) on the keyboard can be disabled.
    ->Increase and decrease the sound-volume.
    ->Listen for keystrokes and send them back to you!
    I would really appreciate if some1 can help me find these codes in java
    thanx
    Alamzaib Shafi
    [email protected]

    Dude, if you did your own homework once in a while you'd be able to handle your own semester project. I hope you fail your class and get kicked out of the program. One less idiot with a diploma competing with us hackers for the tech jobs.
    You are indeed a most worthy recipient of my unemployed angst.

  • Help needed on TCP/IP Multi-port Client-Server

    Hi all, I am trying to develop a client-server application to stream some data over a few random port numbers (defined by myself) to stream data over to the TCP server (i.e another computer) in LabVIEW. So far, I have created my application using the NI examples for "Simple Data Client + Server" and it works fine. I also understand that the "TCP Listen" VI is only able to listen for 1 TCP connection only and a way around this is to use queueing idea to receive & process the incoming data.The downside to the idea is that the "base port" (i.e initial port) needs to be the same (on every TCP client) with the TCP Server and it is not fit for the purpose I intended.
    Basically on the TCP server side, i need to chart/monitor the data on different port numbers that is being streamed real-time from the one TCP client computer. Is this possible in LabVIEW?
    Can anyone (incl. NI gurus) advise and point me in the right direction?
    *lost*
    Solved!
    Go to Solution.

    Hi
        http://zone.ni.com/devzone/cda/epd/p/id/2739 Here you can download that component.But you can also use TCP icons which is available in Data Commmunications>Protocals>TCp for communication and to read and write data use variant to flattened string. I have attached a small example where i will transfer a constant string to the host PC to check the link between client and the server. Hope this helps you.
    Attachments:
    TCP Comm.zip ‏47 KB

  • Does Lync client Inside office need to communicate with Lync Edge Servers?

    Does Lync client Inside office need to communicate with Lync Edge Servers?
    Regards

    Hi,
    Agree with David.
    Here is a similar case may help you:
    https://social.technet.microsoft.com/Forums/en-US/0c10a56a-9669-4ff3-8a76-1769afa61232/lync-client-point-to-point-av-or-conferencing-av-traffic?forum
    Best Regards,
    Eason Huang
    Eason Huang
    TechNet Community Support

  • Design Pattern for multithreaded client server program

    I asked this question in another post, but with other stuff, so I'll distill this one.
    I am creating a multi-threaded client server program (just for learning - a chat program at this point). I built the server and client in swing, and I'm wondering what the best design pattern is for this setup. Right now all the swing stuff is in the MyServer class. In that class I have a loop accepting client connections to the serverSocket and creating a new MyServerThread (threaded client connection).
    The problem is that all the work of creating input streams, interacting with the server, all that stuff is done in the MyServerThread class, but I want that text to be written up to the Swing objects - which is in the MyServer class. So right now in the MyServerThread class I pass the MyServer object into it, but I'm not sure if that is really the most robust thing to do. Does anybody have any suggestions as to how this should be done. If somebody has an article they'd like to point to I'll check it out too. But if it's just the run-of-the-mill multithreaded client-server article, I've read alot and most don't specifically address my question.

    Thanks for the reply Kaj, and I think I'll keep my design for now, since it's just quick and dirty. I've read the MVC concept a while ago and I'll revisit it again when I get more serious. But I have a question, why should I be using a callback interface, why an interface at all? And then make MyServer implement that interface...why not just pass MyServer to the thread object? Or is there something down the line that I did not forsee?

  • Help Needed With Basic Client/Server App

    I was wondering if anyone can help with a simple blackjack client/server application i've been writting (basically its a moddified chat application). The problem i'm having seems to lie within the connection management i've written.
    What i'm trying to get is that only 4 players can connect at one time and that each player takes a turn (which i've implemented using threads) to play their hand (as you would if you were playing it for real). The problem is that it will allow the players to connect, but oddly enough, it will not allow a new transaction to be created (i.e. allow a player to take their turn) until 2 players have connected.
    Even when it does create the transaction, after taking input from the client once, the server seems to stop doing anything without any error message of any kind.
    Its really annoyed me now, so you guys are my last hope!
    The code can be found in full here:
    Client Application: http://stuweb3.cmp.uea.ac.uk/~y0241725/WinEchoClient.java
    Server Application: http://stuweb3.cmp.uea.ac.uk/~y0241725/ThreadServer.java
    Card Class: http://stuweb3.cmp.uea.ac.uk/~y0241725/Card.java
    Deck Class: http://stuweb3.cmp.uea.ac.uk/~y0241725/Deck.java
    Please feel free to play around with this code as much as you feel necessary!

    (one last bump back up the forum before i give up on this completely)

  • Desperately need some help with client-server java programming

    Hi all,
    I'm new to client server java programming. I would like to work on servlets and apache tomcat. I installed the apache tomcat v 5.5 into my machine and i have sun java 6 also. I created a java applet class to be as a client and embed it into an html index file, like this:
    <applet code="EchoApplet.class" width="300" height="300"></applet>However, when I try to run the html file on the localhost, it print this error: classNotFoundException, couldn't load "EchoApplet.class" class. On the other hand, when I open the index file on applet viewer or by right clicking, open with firefox version 3, it works.
    I thought that the problem is with firefox, but after running the applet through the directory not the server, i found that the problem is not any more with firefox.
    Can anyone help me to solve this problem. I'm working on it for 5 days now and nothing on the net helped me. I tried a lot of solutions.
    Any help?

    arun,
    If the browser is going to execute $myApplet, first it must get the $myApplet.class from the server, right?
    So it follows that:
    1. $myApplet.class must be acessible to server, and
    2. the server must know exactly where to find $myApplet.class
    So, the simplest solution is to is put the $myApplet.class in the same directory as the HTML file which uses it... then your applet tag is simple:
      <applet height="200" width="400" code="$myApplet.class" ></applet>* The height & width attributes are required
    * Note the +.class+ is required in the code attribute (a common mistake).
    * This works uniformly (AFAIK) accross all java-enabled browsers.
    * There are incompatibilities with the codebase attribute. Poo!
    Cheers. Keith.

  • Need Help for client - server - client question [Sockets]

    Hi
    I have read the http://java.sun.com/docs/books/tutorial/networking/sockets/index.html tutorial and made this Knock Knock Application.
    But now, I want that one client can view all the other clients which are connected to the server, and interract with a selected cleint over the server (client - server - client).
    But I have no idea how to build such a registration concept?
    A concrete hint (or link) how to realise this would be very helpful. I searched all the internet for examples, but I dont found a simple example.
    Thanks in advance
    greeds

    wSam,
    It appears that Sun considers RMI to be simpler, although less efficient than the alternative:
    http://java.sun.com/developer/technicalArticles/ALT/sockets/
    This article also talks about object serialization, which I am a fan of. Suppose that you want to send a data structure containing lots of information (like all connected users). You can actually pass an object (rather than text) across the network using ObjectOutputStream and receive it on the other end with ObjectInputStream. You might create your own Command class for passing objects between the client and server instead of using RMI. The Command class might hold flags that indicate which method should take place on the remote machine (i.e. send chess move command).

Maybe you are looking for