Problem in Bluetooth client program

Hello, i'm developing a J2ME application. It runs over a mobile phone with Bluetooth and it should connect with an BT Adapter. Mobile phone rol is client, and the adapter is the server.
I have a problem because when mobile phone executes the method public void serviceSearchCompleted(int transID, int respCode) , it stops and doesn't continue with the rest of the code...
I have developed the app. in this way: I finish the process of inquiry, then, i search for services, I find the services in the server, keep them in a vector, and, when the search is completed I call a method called startConnection() that tries to connect with the services found in the server.
However, I have a doubt: Should I call startConnection() when a service is found ( public void servicesDiscovered(int transID,ServiceRecord[] servRecord) ?
I see that when the program calls serviceSearchCompleted all is finished. waht can I do????
Here is the code: ( the inquiry methods are previous, but I don't post it because they run properly...)
public void servicesDiscovered(int transID,ServiceRecord[] servRecord) {
for(int i=0; i<servRecord.length; i++){
ServiceRecord service = servRecord;
servicios_encontrados.addElement(service);
try {
icon = Image.createImage("/icons/BT.jpg");
} catch (Exception e) {
icon = null;
myInfo.setStatus("Enviar ",servicios_encontrados.toString(),icon,AlertType.INFO);
GlucoMidlet.getInstance().showDisplayable(myInfo);
public void serviceSearchCompleted(int transID, int respCode) {
switch(respCode) {
case DiscoveryListener.SERVICE_SEARCH_COMPLETED: System.out.println("Busqueda completada "+"con normalidad");
try {
icon = Image.createImage("/icons/BT.jpg");
} catch (Exception e) {
icon = null;
myInfo.setStatus("Encontrados",servicios_encontrados.size()+"servicios encontrados",icon,AlertType.INFO);
GlucoMidlet.getInstance().showDisplayable(myInfo);
if(servicios_encontrados.size()!=0){
startConnection();
}else{
try {
icon = Image.createImage("/icons/BT.jpg");
} catch (Exception e) {
icon = null;
myInfo.setStatus("Enviar niveles de glucosa","No hay servicios",icon,AlertType.INFO);
GlucoMidlet.getInstance().showDisplayable(myInfo);
break;
case DiscoveryListener.SERVICE_SEARCH_TERMINATED:System.out.println("Busqueda cancelada");
break;
case DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE:System.out.println("Dispositivo no alcanzable");
break;
case DiscoveryListener.SERVICE_SEARCH_NO_RECORDS:System.out.println("No se encontraron registros"+" de servicio");
break;
case DiscoveryListener.SERVICE_SEARCH_ERROR:System.out.println("Error en la busqueda");
break;
public void startConnection(){
for (int i=servicios_encontrados.indexOf(servicios_encontrados.firstElement()); i<=servicios_encontrados.indexOf(servicios_encontrados.lastElement());i++ ){
btconnect((ServiceRecord)servicios_encontrados.elementAt(i));
public void btconnect (final ServiceRecord sr){
Thread th = new Thread() {
public void run() {
String url = sr.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
StreamConnection connection = null;
ByteArrayInputStream bais = null;
ByteArrayOutputStream baos = null;
try {
connection =(StreamConnection) Connector.open(url);
bais = (ByteArrayInputStream) connection.openInputStream();
baos = (ByteArrayOutputStream) connection.openOutputStream();
} catch(IOException exp){
ActionsController.notifyException("Error al transferir datos, IMPORTANTE.");}
send_command(connection,bais,baos,ID,url);
send_command(connection,bais,baos,GET_METER,url);
send_events(connection,bais,baos,GET_EVENTS);
cancelar(); //cancelamos las busquedas
/* } finally {
try {
if(bais != null)
bais.close();
if(baos != null)
baos.close();
if(connection != null)
connection.close();
} catch(IOException e) {}
th.start();

jaime_zgz
Just a thought.
The loop in your startConnection() sequentially attempts to connect to all discovered services. This may not be supported. One service may need to be disconnected in order to connect to another.
OK since each attempt is in a new Thread, it should throw a IOException for those attempts that fail on this account, but maybe you could simplify it and attempt to connect to just one service, and see what you get.
I have limited experience in BT, so don't trust me on everything :-) but ohterwise your code looks OK.
All the best, Darryl

Similar Messages

  • Problem while running client program in Netbeans4.0

    Hi,
    I am facing the following problem while running a client program in Nebeans4.0.
    An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x7C9012B4
    Function=RtlInitAnsiString+0x1B
    Library=C:\WINDOWS\system32\ntdll.dll
    Current Java thread:
    at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:770)
    at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1059)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1009)
    at java.net.InetAddress.getAllByName0(InetAddress.java:981)
    at java.net.InetAddress.getAllByName(InetAddress.java:975)
    at weblogic.rjvm.RJVMFinder.getDnsEntries(RJVMFinder.java:370)
    at weblogic.rjvm.RJVMFinder.findOrCreate(RJVMFinder.java:181)
    - locked <0x1007ff78> (a weblogic.rjvm.RJVMFinder)
    at weblogic.rjvm.ServerURL.findOrCreateRJVM(ServerURL.java:125)
    at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:291)
    at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:234)
    at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:135)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
    at javax.naming.InitialContext.init(InitialContext.java:219)
    at javax.naming.InitialContext.<init>(InitialContext.java:195)
    at AcfClient.getHomeRef(AcfClient.java:73)
    at AcfClient.forceSession(AcfClient.java:43)
    at AcfClient.main(AcfClient.java:34)
    Dynamic libraries:
    0x00400000 - 0x00406000      C:\Data\j2sdk1.4.2_04\jre\bin\java.exe
    0x7C900000 - 0x7C9B0000      C:\WINDOWS\system32\ntdll.dll
    0x7C800000 - 0x7C8F4000      C:\WINDOWS\system32\kernel32.dll
    0x77DD0000 - 0x77E6B000      C:\WINDOWS\system32\ADVAPI32.dll
    0x77E70000 - 0x77F01000      C:\WINDOWS\system32\RPCRT4.dll
    0x77C10000 - 0x77C68000      C:\WINDOWS\system32\MSVCRT.dll
    0x08000000 - 0x08138000      C:\Data\j2sdk1.4.2_04\jre\bin\client\jvm.dll
    0x77D40000 - 0x77DD0000      C:\WINDOWS\system32\USER32.dll
    0x77F10000 - 0x77F56000      C:\WINDOWS\system32\GDI32.dll
    0x76B40000 - 0x76B6D000      C:\WINDOWS\system32\WINMM.dll
    0x6BD00000 - 0x6BD0D000      C:\WINDOWS\system32\SYNCOR11.DLL
    0x10000000 - 0x10007000      C:\Data\j2sdk1.4.2_04\jre\bin\hpi.dll
    0x00390000 - 0x0039E000      C:\Data\j2sdk1.4.2_04\jre\bin\verify.dll
    0x003B0000 - 0x003C9000      C:\Data\j2sdk1.4.2_04\jre\bin\java.dll
    0x003D0000 - 0x003DD000      C:\Data\j2sdk1.4.2_04\jre\bin\zip.dll
    0x02DA0000 - 0x02DAF000      C:\Data\j2sdk1.4.2_04\jre\bin\net.dll
    0x71AB0000 - 0x71AC7000      C:\WINDOWS\system32\WS2_32.dll
    0x71AA0000 - 0x71AA8000      C:\WINDOWS\system32\WS2HELP.dll
    0x71A50000 - 0x71A8F000      C:\WINDOWS\System32\mswsock.dll
    0x76F20000 - 0x76F47000      C:\WINDOWS\system32\DNSAPI.dll
    0x76FB0000 - 0x76FB8000      C:\WINDOWS\System32\winrnr.dll
    0x76F60000 - 0x76F8C000      C:\WINDOWS\system32\WLDAP32.dll
    0x66210000 - 0x66219000      C:\WINDOWS\system32\netware\NWWS2NDS.DLL
    0x50D50000 - 0x50D95000      C:\WINDOWS\system32\NETWIN32.DLL
    0x50D00000 - 0x50D15000      C:\WINDOWS\system32\CLNWIN32.DLL
    0x50DF0000 - 0x50E10000      C:\WINDOWS\system32\LOCWIN32.DLL
    0x50DB0000 - 0x50DD9000      C:\WINDOWS\system32\NCPWIN32.dll
    0x71AD0000 - 0x71AD9000      C:\WINDOWS\system32\WSOCK32.dll
    0x66220000 - 0x6622C000      C:\WINDOWS\system32\netware\NWWS2SLP.DLL
    0x1C000000 - 0x1C007000      C:\WINDOWS\system32\NWSRVLOC.dll
    0x76C90000 - 0x76CB8000      C:\WINDOWS\system32\imagehlp.dll
    0x59A60000 - 0x59B01000      C:\WINDOWS\system32\DBGHELP.dll
    0x77C00000 - 0x77C08000      C:\WINDOWS\system32\VERSION.dll
    0x76BF0000 - 0x76BFB000      C:\WINDOWS\system32\PSAPI.DLL
    Heap at VM Abort:
    Heap
    def new generation total 576K, used 497K [0x10010000, 0x100b0000, 0x104f0000)
    eden space 512K, 89% used [0x10010000, 0x10083158, 0x10090000)
    from space 64K, 57% used [0x100a0000, 0x100a9478, 0x100b0000)
    to space 64K, 0% used [0x10090000, 0x10090000, 0x100a0000)
    tenured generation total 1408K, used 129K [0x104f0000, 0x10650000, 0x14010000)
    the space 1408K, 9% used [0x104f0000, 0x10510438, 0x10510600, 0x10650000)
    compacting perm gen total 4096K, used 2122K [0x14010000, 0x14410000, 0x18010000)
    the space 4096K, 51% used [0x14010000, 0x14222828, 0x14222a00, 0x14410000)
    Local Time = Fri Aug 26 10:26:03 2005
    Elapsed Time = 2
    # The exception above was detected in native code outside the VM
    # Java VM: Java HotSpot(TM) Client VM (1.4.2_04-b05 mixed mode)
    # An error report file has been saved as hs_err_pid1280.log.
    # Please refer to the file for further information.
    Can anyone pls let me know what could be the problem.
    Thanks in adv.

    Hi,
    This type of error
    java.lang.NoClassDefFoundError: javax/naming/Context
    will occur when the client program could not able to locate lib/j2EE.jar file.
    So set the classpath correctly and make sure that you have correctly defined the JAVA_HOME environment variable in .bat script.
    Hope this will help you.
    Regards,
    Anil.
    Technical Support Engineer.

  • Ftp Client program problem ...

    Hi all .
    I m trying to develope a simple FTP client program which will connect to the FTP server for download a file .. Now in the start i m just trying to get the current directory of the server using -- pwd -- command . My programs executes correct , but the Temporary file in which i m trying to store the outpur from server displays INVALID COMMAND (for my command) - and INVALID LOGIN (for user name) ---. What i think is there is a prlem with the syntax of my FTP configuration file .
    There are three files in the program:
    1.FTPClient.java
    2.ftp.txt (FTP Configuration File)
    3.temp.txt (File for storing the output from server)
    ----------- code for the JAVA file --------
    import java.net.*;
    import java.io.*;
    public class FtpClient {
    public static void main(String args[]) {
    try {
    Runtime rt = Runtime.getRuntime();
    String tempFile = "temp.txt";
    Process pr = rt.exec("ftp -s:ftp.txt 190.166.1.9");
    PrintStream out = new PrintStream(new FileOutputStream(tempFile),true);
    BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String line;
    while((line=in.readLine()) != null)
    out.println(line);
    out.flush();
    out.close();
    in.close();
    pr.destroy();
    } //closes try
    catch (Exception e)
    {System.out.println(e.toString());}
    } // closes main
    -------------------- my FTP Configuration File (ftp.txt) -------------
    USER <computer>
    PASS <javame>
    pwd
    BYE
    ------------OUT PUT in my temp.txt FILE -----------
    User (190.166.1.9:(none)):
    Login incorrect.
    Invalid command.
    <javame>
    pwd
    530 Please login with USER and PASS.
    BYE

    Cross post
    http://forum.java.sun.com/thread.jspa?threadID=595231&messageID=3139200#3139200

  • How can connect different ejb server in one client program

    hi , every
    i want to make connect ejb server into one client program.
    for that , but i try to change PROVIDER_URL property , it's not correct
    who solve this problem for novice? :(

    You need to create separate initialContext to each of the different servers
    and lookup up the different ejbs.
    -Sabha
    "inking" <[email protected]> wrote in message
    news:[email protected]..
    hi , every
    i want to make connect ejb server into one client program.
    for that , but i try to change PROVIDER_URL property , it's not correct
    who solve this problem for novice? :(

  • Problem in executing client application as windows service

    Hi
    I have a client program that sends client ip address to server.
    My Requirement is to run this client program as windows service.
    For this, i have created a jar and after that i have created a .exe file.
    now using sc command in DOS i was created a service named as ClientService
    But when i am trying to start this service like other services, it is giving error saying that "The Service did not respond to the start in a timely fashion"
    Please help me in this issue

    1.Can i lock my mobile phone from J2Me Application.In J2ME you can not.
    2.How can i register J2ME application as service,means
    it started when mobile start and continously Run on my
    mobile. can these problem have a solution ,if yes then
    how..I haven't seen any device that lets you run a J2ME app at start up as a service like windowsNT. May be you can do the above two things if you dig more in to Symbian OS programming.
    Good luck
    Manas

  • Error in running client program

    hi , i am tring to run a sample client program for web service
    i am getting the following error:
    Exception in thread "main" java.lang.NoClassDefFoundError: BatchWebServices/axis
    /browsing/Sample1 (wrong name: browsing/Sample1)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: BatchWebServices.axis.browsing.Sample1. Program
    will exit.
    can any one please help

    Dear all,
    I just tried my RMI examples downloaded from http://java.sun.com/j2se/1.5.0/docs/guide/rmi/ and I got exactly the same java.rmi UnmarshalException.
    Could you still pay attension to this problem and provide a solution?
    Best regards,
    PY

  • Error while running client program

    Hi,
    I am writing a sample program. Below is the server code.
    package helloWorld;
    import javax.jws.*;
    @WebService
    public class HelloWorld {
         @WebMethod
         public String hello() {
              System.out.println("Print data");
              return "Test";
    Firstly when I start the server I get
    <WSEE>Warning: JMS Queue 'weblogic.wsee.DefaultQueue' is not found, as a result, Web Service async responses via jms transport is not supported. If the target service uses JMS transport, the responses will not be able to come back.<JmsQueueListener.connect:227>
    Ignoring this I wrote a client program
    package web;
    import java.io.IOException;
    import java.io.PrintWriter;
    * Servlet implementation class for Servlet: WebClient
    public class WebClient {
              public static void main(String[] argc)
              try {
                   HelloWorldService_Impl service = new HelloWorldService_Impl();
                   HelloWorld port = service.getHelloWorldSoapPort();
                   java.lang.String message = "Hi";
                   // TODO process result here
                   String result = port.hello();
                   System.out.println("Result = "+result);
              }catch(Exception e)
                   e.printStackTrace();
    When I run the client I get runtime error
    D:\test\2105\WebClient\src>D:\bea\jdk150_04\bin\java -cp .;jaxrpc.jar;weblogic.jar;webservices.jar;webservicesclient.jar;xbean.jar;ant.jar;ant-antlr.jar;ant-weblogic.jar web/WebClient
    Exception in thread "main" java.lang.AssertionError: java.io.IOException
    at weblogic.descriptor.DescriptorManager$DefaultMarshallerFactorySingleton.<clinit>(DescriptorManager.java:42)
    at weblogic.descriptor.DescriptorManager.getDefaultMF(DescriptorManager.java:116)
    at weblogic.descriptor.DescriptorManager.getMarshallerFactory(DescriptorManager.java:125)
    at weblogic.descriptor.DescriptorManager.getDescriptorFactory(DescriptorManager.java:147)
    at weblogic.descriptor.DescriptorManager.createDescriptor(DescriptorManager.java:215)
    at weblogic.descriptor.DescriptorManager.createDescriptor(DescriptorManager.java:185)
    at weblogic.descriptor.DescriptorManager.createDescriptor(DescriptorManager.java:170)
    at weblogic.wsee.jaxrpc.ServiceImpl.loadWeblogicDD(ServiceImpl.java:404)
    at weblogic.wsee.jaxrpc.ServiceImpl.loadInternalDD(ServiceImpl.java:346)
    at weblogic.wsee.jaxrpc.ServiceImpl.<init>(ServiceImpl.java:110)
    at web.HelloWorldService_Impl.<init>(HelloWorldService_Impl.java:21)
    at web.HelloWorldService_Impl.<init>(HelloWorldService_Impl.java:13)
    at web.WebClient.main(WebClient.java:15)
    Caused by: java.io.IOException
    at weblogic.descriptor.internal.MarshallerFactory.<init>(MarshallerFactory.java:50)
    at weblogic.descriptor.DescriptorManager$DefaultMarshallerFactorySingleton.<clinit>(DescriptorManager.java:40)
    ... 12 more
    Caused by: com.bea.xml.XmlException: unable to load type library from classloader sun.misc.Launcher$AppClassLoader@e39a3e
    at com.bea.staxb.runtime.internal.BindingContextFactoryImpl.createBindingContext(BindingContextFactoryImpl.java:50)
    at weblogic.descriptor.internal.MarshallerFactory.<init>(MarshallerFactory.java:48)
    Can anyone let me know what could be the problem?

    Hi,
    My Client Program is as follows:
    import javax.ejb.*;
    public class Client{
    public static void main(String[] args){
    Account account = null;
         try{
    Context = new
    Context = new
    InitialContext(System.getProperties());
    AccountHome home = (AccountHome)
    AccountHome)
    ctx.lookup("java:comp/env/ejb/AccountBean");
         home.create("123-456-7890","John");
         }catch(...){
    }What are the System Properties? Are you running the client remotely? Are you running the client as a stand alone Java app or using the Weblogic's Client Runner? 'java:comp' as the jndi name is usually used when the client runs inside the container... But it doesn't seem to be the case.
    Kexkey

  • Error When running the Client Program

    hi all,
    i got exception while running the Client program
    "Cannot instantiate class: weblogic.jndi.WLInitialContextFactory [Root exception is java.lang.ClassNotFoundException: weblogic.jndi.WLInitialContextFactory]"
    plz solve my problem ASAP.
    thanks in advance..
    from
    sree

    thanks this problem solved...
    but i got another exception
    javax.naming.NameNotFoundException: Unable to resolve 'ExeBean' Resolved: '' Unresolved:'ExeBean' ; remaining name 'ExeBean'
    thanks in advance
    from
    Sree

  • Compilation errors when using Client program

    Hi all,
    I face a problem when compiling the client.
    Compilation errors:
    "Not able to resolve symbols HelloHome, Hello"
    At this line: HelloHome home = (HelloHome)ctx.lookup("HelloHome")
    I have cut and paste the client program below:
    Please look into it.
    Thanks
    Ranjan
    //Client for HelloBean
    import java.rmi.*;
    import javax.naming.*;
    import java.util.*;
    public class HelloClient {
    public static void main(String args[]) {
    try
    Hashtable ht = new Hashtable();
    ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
    InitialContext ctx = null;
    ctx = new InitialContext(ht);
    HelloHome home = (HelloHome)ctx.lookup("HelloHome");
    Hello hel = home.create();
    String retval = hel.sayHello("Ranjan");
    System.out.println("Returned: " + retval);
    hel.remove();
    catch (RemoteException e)
    System.out.println("RemoteException occured: " + e);
    catch (javax.ejb.CreateException e)
    System.out.println("Create Exception occured: " + e);
    catch (javax.ejb.RemoveException e)
    System.out.println("Remove Exception occured: " + e);
    catch(javax.naming.NamingException e)
    System.out.println("Naming Exception occured: " + e);
    **************************

    Hi,
    Yes the Hello and HelloHome classes are present in the same directory as the HelloClient.class
    Regards
    Ranjan

  • Using Windows NT 4.0 client program connecting to oracle 8i linux server

    Dear sir/madam,
    Recently, I have successfully installed Oracle 8i in my red hat linux database server. I am disappointed because I can find client side Oracle Enterprise Manager in my linux server even I have installed client program in my linux database server.
    Next, I install Oracle 8i client side program (windows NT/2000 version) in my Windows NT 4.0 server. I am still disappointed because I find Oracle Enterprise Manager console cannot work.
    For Windows NT 4.0 Enterprise Manager, I have key in default administrator sysman, password oem_temp, and connect to mamagement server hangng (my linux database server). An error message display 'VTK-1000 Unable to connect to the management server hangng. Please verify that you have entered the correct host name and the status of the Oracle Management Server.'.
    What's wrong with both Oracle 8i Management Server in linux database server and windows nt 4.0 server. Is there any problem for Oracle Management server console to connect to red hat linux database server?

    [email protected] wrote:
    I need to confirm that I will be able to connect an Oracle 11g R2 client (administrator install) to an Oracle 8i DB before i bother trying to setup such a scenario?Don't waste your time. It won't work. It simply results in an error.
    I saw another thread that mentioned a patch level required for 8i to let the 10g client connect. Is there such a patch level needed for 11g clients as well?There is no such patch for 8i which allows 11g client to connect.

  • Problem using CORBA clients with RMI/EJB servers..!!!???

    Hi,
    I have a question on using EJB / or RMI servers with CORBA clients using
    RMI-IIOP transport, which in theory should work, but in practice has few
    glitches.
    Basically, I have implemented a very simple server, StockTreader, which
    looks up for a symbol and returns a 'Stock' object. In the first example, I
    simplified the 'Stock' object to be a mere java.lang.String, so that lookup
    would simply return the 'synbol'.
    Then I have implemented the above, as an RMI-IIOP server (case 1) and a
    CORBA server (case 2) with respective clients, and the pair of
    client-servers work fine as long as they are CORBA-to-CORBA and RMI-to-RMI.
    But the problem arises when I tried using the RMI server (via IIOP) with the
    CORBA client, when the client tries to narrow the object ref obtained from
    the naming service into the CORBA idl defined type (StockTrader) it ends up
    with a class cast exception.
    This is what I did to achieve the above results:
    [1] Define an RMI interface StockTrader.java (extending java.rmi.Remote)
    with the method,
    public String lookup( String symbol) throws RMIException;
    [2] Implement the StorckTrader interface (on a PortableRemoteObject derived
    class, to make it IIOP compliant), and then the server to register the stock
    trader with COS Naming service as follows:
    String homeName =....
    StockTraderImpl trader =new StockTraderImpl();
    System.out.println("binding obj <" homeName ">...");
    java.util.Hashtable ht =new java.util.Hashtable();
    ht.put("java.naming.factory.initial", args[2]);
    ht.put("java.naming.provider.url", args[3]);
    Context ctx =new InitialContext(ht);
    ctx.rebind(homeName, trader);
    [3] Generate the RMI-IIOP skeletons for the Implementation class,
    rmic -iiop stock.StockTraderImpl
    [4] generate the IDL for the RMI interface,
    rmic -idl stock.StockTraderImpl
    [5] Generate IDL stubs for the CORBA client,
    idlj -v -fclient -emitAll StockTraderImpl.idl
    [6] Write the client to use the IDL-defined stock trader,
    String serverName =args[0];
    String symList =args[1];
    StockClient client =new StockClient();
    System.out.println("init orb...");
    ORB orb =ORB.init(args, null);
    System.out.println("resolve init name service...");
    org.omg.CORBA.Object objRef
    =orb.resolve_initial_references("NameService");
    NamingContext naming =NamingContextHelper.narrow(objRef);
    ... define a naming component etc...
    org.omg.CORBA.Object obj =naming.resolve(...);
    System.out.println("narrow objRef: " obj.getClass() ": " +obj);
    StockTrader trader =StockTraderHelper.narrow(obj);
    [7] Compile all the classes using Java 1.2.2
    [8] start tnameserv (naming service), then the server to register the RMI
    server obj
    [9] Run the CORBA client, passing it the COSNaming service ref name (with
    which the server obj is registered)
    The CORBA client successfully finds the server obj ref in the naming
    service, the operation StockTraderHelper.narrow() fails in the segment
    below, with a class cast exception:
    org.omg.CORBA.Object obj =naming.resolve(...);
    StockTrader trader =StockTraderHelper.narrow(obj);
    The <obj> returned by naming service turns out to be of the type;
    class com.sun.rmi.iiop.CDRInputStream$1
    This is of the same type when stock trader object is registered in a CORBA
    server (as opposed to an RMI server), but works correctly with no casting
    excpetions..
    Any ideas / hints very welcome.
    thanks in advance,
    -hari

    On the contrary... all that is being said is that we needed to provide clearer examples/documentation in the 5.1.0 release. There will be no difference between the product as found in the service pack and the product found in the 5.1.1. That is, the only substantive will be that 5.1.1 will also
    include the examples.
    "<=one way=>" wrote:
    With reference to your and other messages, it appears that one should not
    expect that WLS RMI-IIOP will work in a complex real-life system, at least
    not now. In other words, support for real-life CORBA clients is not an
    option in the current release of WLS.
    TIA
    "Eduardo Ceballos" <[email protected]> wrote in message
    news:[email protected]...
    We currently publish an IDL example, even though the IDL programmingmodel in Java is completely non-functional, in anticipation of the support
    needs for uses who need to use IDL to talk to the Weblogic server,
    generically. This example illustrates the simplest connectivity; it does not
    address how
    to integrate CORBA and EJB, a broad topic, fraught with peril, imo. I'llnote in passing that, to my knowledge, none of the other vendors attempt
    this topic either, a point which is telling if all the less happy to hear.
    For the record then, what is missing from our distribution wrt RMI-IIOPare a RMI-IIOP example, an EJB-IIOP example, an EJB-C++. In this you are
    correct; better examples are forth coming.
    Still, I would not call our RMI-IIOP implementation fragile. I would saythat customers have an understandably hard time accepting that the IDL
    programming model is busted; busted in the sense that there are no C++
    libraries to support the EJB model, and busted in the sense that there is
    simply no
    support in Java for an IDL interface to an EJB. Weblogic has nothing to doit being busted, although we are trying to help our customers deal with it
    in productive ways.
    For the moment, what there is is a RMI (over IIOP) programming model, aninherently Java to Java programming model, and true to that, we accept and
    dispatch IIOP request into RMI server objects. The way I look at it is this:
    it's just a protocol, like HTTP, or JRMP; it's not IDL and it has
    practically nothing to do with CORBA.
    ST wrote:
    Eduardo,
    Can you give us more details about the comment below:
    I fear that as soon as the call to narrow succeeds, the remainingapplication will fail to work correctly because it is too difficult ot
    use an idl client in java to work.It seems to me that Weblogic's RMI-IIOP is a very fragile
    implementation. We
    don't need a "HelloWorld" example, we need a concrete serious example(fully
    tested and seriously documented) that works so that we can get a betteridea
    on how to integrate CORBA and EJB.
    Thanks,
    Said
    "Eduardo Ceballos" <[email protected]> wrote in message
    news:[email protected]...
    Please post request to the news group...
    As I said, you must separate the idl related classes (class files and
    java
    files) from the rmi classes... in the rmic step, you must set a newtarget
    (as you did), emit the java files into that directory (it's not clearyou
    did this), then remove all the rmi class files from the class path... ifyou
    need to compile more classes at that point, copy the java files to theidl
    directly is you must, but you can not share the types in any way.
    I fear that as soon as the call to narrow succeeds, the remainingapplication will fail to work correctly because it is too difficult otuse
    an idl client in java to work.
    Harindra Rajapakshe wrote:
    Hi Eduardo,
    Thanks for the help. That is the way I compiled my CORBA client, by
    separating the IDL-generated stubs from the RMI ones, but still I
    get a
    CORBA.BAD_PARAM upon narrowing the client proxy to the interfacetype.
    Here's what I did;
    + Define the RMI interfaces, in this case a StockTrader interface.
    + Implement RMI interface by extendingjavax.rmi.PortableRemoteObject
    making
    it IIOP compliant
    + Implemnnt an RMI server, and compile using JDK1.2.2
    + use the RMI implementation to generate CORBA idl, using RMI-IIOPplugin
    utility rmic;
    rmic -idl -noValueMethods -always -d idl stock.StockTraderImpl
    + generate Java mappings to the IDL generated above, using RMI-IIOPplugin
    util,
    idlj -v -fclient -emitAll -tf src stocks\StockTrader.idl
    This creates source for the package stock and also
    org.omg.CORBA.*
    package, presumably IIOP type marshalling
    + compile all classes generated above using JDK1.2.2
    + Implement client (CORBA) using the classes generated above, NOTthe
    RMI
    proxies.
    + start RMI server, with stockTrader server obj
    + start tnameserv
    + start CORBA client
    Then the client errors when trying to narrow the obj ref from the
    naming
    service, into the CORBA IDL defined interface using,
    org.omg.CORBA.Object obj =naming.resolve(nn);
    StockTrader trader =StockTraderHelper.narrow(obj); // THIS
    ERRORS..!!!
    throwing a CORBA.BAD_PARAM exception.
    any ideas..?
    Thanks in advance,
    -hari
    ----- Original Message -----
    From: Eduardo Ceballos <[email protected]>
    Newsgroups: weblogic.developer.interest.rmi-iiop
    To: Hari Rajapakshe <[email protected]>
    Sent: Wednesday, July 26, 2000 4:38 AM
    Subject: Re: problem using CORBA clients with RMI/EJBservers..!!!???
    Please see the post on june 26, re Errors compiling... somewherein
    there,
    I suspect, you are referring to the rmi class file when you are
    obliged
    to
    completely segregate these from the idl class files.
    Hari Rajapakshe wrote:
    Hi,
    I have a question on using EJB / or RMI servers with CORBA
    clients
    using
    RMI-IIOP transport, which in theory should work, but in practice
    has
    few
    glitches.
    Basically, I have implemented a very simple server,
    StockTreader,
    which
    looks up for a symbol and returns a 'Stock' object. In the firstexample, I
    simplified the 'Stock' object to be a mere java.lang.String, so
    that
    lookup
    would simply return the 'synbol'.
    Then I have implemented the above, as an RMI-IIOP server (case
    1)
    and a
    CORBA server (case 2) with respective clients, and the pair of
    client-servers work fine as long as they are CORBA-to-CORBA andRMI-to-RMI.
    But the problem arises when I tried using the RMI server (via
    IIOP)
    with
    the
    CORBA client, when the client tries to narrow the object ref
    obtained
    from
    the naming service into the CORBA idl defined type (StockTrader)
    it
    ends
    up
    with a class cast exception.
    This is what I did to achieve the above results:
    [1] Define an RMI interface StockTrader.java (extending
    java.rmi.Remote)
    with the method,
    public String lookup( String symbol) throws RMIException;
    [2] Implement the StorckTrader interface (on a
    PortableRemoteObject
    derived
    class, to make it IIOP compliant), and then the server to
    register
    the
    stock
    trader with COS Naming service as follows:
    String homeName =....
    StockTraderImpl trader =new StockTraderImpl();
    System.out.println("binding obj <" homeName ">...");
    java.util.Hashtable ht =new java.util.Hashtable();
    ht.put("java.naming.factory.initial", args[2]);
    ht.put("java.naming.provider.url", args[3]);
    Context ctx =new InitialContext(ht);
    ctx.rebind(homeName, trader);
    [3] Generate the RMI-IIOP skeletons for the Implementation
    class,
    rmic -iiop stock.StockTraderImpl
    [4] generate the IDL for the RMI interface,
    rmic -idl stock.StockTraderImpl
    [5] Generate IDL stubs for the CORBA client,
    idlj -v -fclient -emitAll StockTraderImpl.idl
    [6] Write the client to use the IDL-defined stock trader,
    String serverName =args[0];
    String symList =args[1];
    StockClient client =new StockClient();
    System.out.println("init orb...");
    ORB orb =ORB.init(args, null);
    System.out.println("resolve init name service...");
    org.omg.CORBA.Object objRef
    =orb.resolve_initial_references("NameService");
    NamingContext naming=NamingContextHelper.narrow(objRef);
    ... define a naming component etc...
    org.omg.CORBA.Object obj =naming.resolve(...);
    System.out.println("narrow objRef: " obj.getClass() ":"
    +obj);
    StockTrader trader =StockTraderHelper.narrow(obj);
    [7] Compile all the classes using Java 1.2.2
    [8] start tnameserv (naming service), then the server to
    register
    the
    RMI
    server obj
    [9] Run the CORBA client, passing it the COSNaming service ref
    name
    (with
    which the server obj is registered)
    The CORBA client successfully finds the server obj ref in the
    naming
    service, the operation StockTraderHelper.narrow() fails in thesegment
    below, with a class cast exception:
    org.omg.CORBA.Object obj =naming.resolve(...);
    StockTrader trader =StockTraderHelper.narrow(obj);
    The <obj> returned by naming service turns out to be of the
    type;
    class com.sun.rmi.iiop.CDRInputStream$1
    This is of the same type when stock trader object is registeredin a
    CORBA
    server (as opposed to an RMI server), but works correctly with
    no
    casting
    excpetions..
    Any ideas / hints very welcome.
    thanks in advance,
    -hari

  • Problem running Java client of EJB deployed on WebSphere

    Hi,
    I am using websphere studio 5.1.2 with fix pack 3. I have a sample Stateless Session Bean (EJB) deployed and running on websphere.
    I wrote a small Java client program as below.
    import java.util.Hashtable;
    import HelloJavaHome;
    import HelloJava;
    import javax.naming.InitialContext;
    import javax.naming.Context;
    import javax.ejb.EJBHome;
    import javax.ejb.EJBObject;
    public class RemoteConn {
    public static void main(String[] ar) throws Exception{
    String greeting = "";
    try{
    Hashtable env = new Hashtable();
    //env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
    //env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ejs.ns.jndi.CNInitialContextFactory");
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ws.naming.util.WsnInitCtxFactory");
    //env.put(Context.PROVIDER_URL, "corbaloc:iiop:myhost.mycompany.com:2809/NameServiceCellPersistentRoot");
    env.put(Context.PROVIDER_URL, "iiop://localhost:2809");
    System.out.println("Before creating context ");
    InitialContext initContext = new InitialContext(env);
    System.out.println("Before looking up HelloJavaHome.");
    //Object obj = initContext.lookup("java:comp/env/ejb/HelloJavaHome");
    Object obj = initContext.lookup("ejb/HelloJavaHome");
    System.out.println("After lookup javahome.");
    HelloJavaHome home = (HelloJavaHome) javax.rmi.PortableRemoteObject.narrow(obj, HelloJavaHome.class);
    HelloJava remote = home.create();
    greeting = remote.getGreeting("John");
    catch(Exception e){
    e.printStackTrace();
    System.out.println("Greeting::"+ greeting);
    I did not have any problem if I write and run this client from Websphere studio environment..
    However its giving lot of compilation and runtime errors when I tried to run from command line.
    I could eliminated compilation errors by setting the below jar files in the classpath.
    testclient.jar; (client jar of my EJB)
    j2ee.jar;
    naming.jar;ras.jar;
    wsexception.jar;
    bootstrap.jar;
    namingclient.jar;
    websphere.jar;server.jar;
    ejbcontainer.jar;
    ecutils.jar;
    Now it is throwing runtime error after the statement, "Before looking up HelloJavaHome.", has printed. Here is the stack trace of exception ..
    Exception in thread "main" java.lang.NoClassDefFoundError: com.ibm.CORBA.iiop.GlobalORBFactory
    at com.ibm.ejs.oa.EJSORBImpl.class$(EJSORBImpl.java:44)
    at com.ibm.ejs.oa.EJSORBImpl.initializeORB(EJSORBImpl.java:195)
    at com.ibm.ejs.oa.EJSClientORBImpl.(EJSClientORBImpl.java:93)
    at com.ibm.ejs.oa.EJSClientORBImpl.(EJSClientORBImpl.java:65)
    at com.ibm.ejs.oa.EJSORB.init(EJSORB.java:385)
    at com.ibm.ws.naming.util.Helpers.getOrb(Helpers.java:284)
    at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:369)
    at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:112)
    at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:422)
    at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:143)
    at javax.naming.InitialContext.lookup(InitialContext.java:347)
    at RemoteEJBConn.main(RemoteEJBConn.java:38)
    I appreciate if sombody could help me ASAP fixing this problem.
    Thanks in advance.

    Try using the IBM JVM (theres one shipped with WebSphere in websphere_home\AppServer\java
    Also include idl.jar and ffdc.jar on the classpath

  • Error running client program

    c:>java HelloClient
    Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/logging/LogO
    utputStream
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:124)
    at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialCont
    extFactory.java:118)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
    71)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:242
    at javax.naming.InitialContext.init(InitialContext.java:218)
    at javax.naming.InitialContext.<init>(InitialContext.java:194)
    at HelloClient.main(HelloClient.java:17)
    I am gettting the following error when run the client program
    i am using weblogic 5.1
    the code is HelloClient.java
    import java.rmi.RemoteException;
    import java.util.Properties;
    import javax.ejb.CreateException;
    import javax.ejb.RemoveException;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.rmi.PortableRemoteObject;
    public class HelloClient {
    public static void main(String [] args) {
    try {
    Properties props=new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    props.put(Context.PROVIDER_URL,"t3://localhost:7001");
    InitialContext ctx = new InitialContext(props);
    Object ref = ctx.lookup("helloBean.HelloHome");
    HelloHome hello1 =
    (HelloHome)PortableRemoteObject.narrow(ref,HelloHome.class);
    Hello1 helloHome = hello1.create();
    String message = helloHome.getMessage();
    System.out.println("messsage from Bean====" +message);
    // helloHome.remove(); //clean up
    catch (NamingException ne){
    ne.printStackTrace();}
    catch (Exception exception) {
    System.err.println("Exception!");
    exception.printStackTrace();}
    Hello1 is remote interface
    HelloHome is home inteerface
    the bean is deployed
    anyone please help
    i hava added c:\weblogic\classes\weblogic\logging in classs path
    but the same problem occured.

    Try addinging weblogic.jar to the classpath.

  • Error in Executing EJB Client Program

    Hai
    I am Kranthi kumar,encountered an error message when trying to compile the client program.It said NO NAMING.CONTEXT IN NAMING DIRECTORY. But when i was looking up for that naming directory i could not find that.Please let me know where i can find the Context and Initial Context class files in the weblogic.I am working on Weblogic 5.1.Please solve my problem.
    Thanking you
    S.kranthi kumar

    Use this method,
      public Context getInitialContext() throws Exception {
        Properties p = new Properties();
        String url = "t3://206.251.112.49:7001"
        p.put(Context.INITIAL_CONTEXT_FACTORY,
              "weblogic.jndi.WLInitialContextFactory");
        p.put(Context.PROVIDER_URL, url);
        return new InitialContext(p);
    }and
    try {
         Context ctx = getInitialContext();
        Your_Ejb_Home home = (Your_Ejb_Home) ctx.lookup("your_ejb_home_binding_name");
    } catch(Exception e){
         //Handle exception
    }Hope this helps.
    Sudha

  • Need an example of server / client program with swing interface

    Hi!
    After a lot of trying i still haven't managed to create a server client program using swing components ...
    can someone write a mini application to demonstrate how this can be done?
    i would like to have a frame with a button a texField for input and a textAread for the output
    What i have in mind is the following ..
    say im the server
    i write something in the textField and then i press the button
    then the information written in the textFiled is passed to the client who shows it in his textArea
    The same thing goes on with the client (he can write something in his own textField and when he presses the button the info is passed at the
    server who puts it in his textArea) and vice versa.
    i have written many classes that trying unsuccessfully to do that ... below i show my last attempt ...
    I would appreciate if you could write a small application which it could to this.
    The whole idea is to create a turn based game ( i have implemented the game engine and graphics and i try to add the internet function)
    Here is the code ...( i would appreciate if you write a new code instead of trying to correct mine ( which i think it's impossible) in order to use it as a general example)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    @SuppressWarnings("serial")
    *  In order to have a more gereral program instead of passing strings between the server
    *  and the client a pass an MyObjext object.  The MyObject class has an integer and a String
    *  (which is always the same) field . At the textField i write an integer number and i
    *  make a new MyObject which i want to pass to the server or the client and vice versa.
    *  The textArea shows the integer value of the MyObject which was passed from the server /client
    public class MyUserInterface extends JFrame {
         MyObject returnObject;
         JTextField myTextField;
         JTextArea te ;
         ClientGame cg;
         ServerGame sg;
          * used to determine if the current instance is running as a client or host
         boolean isHost;
         //The constructor of the client
         public MyUserInterface(ClientGame cg){
              this("Client");
              this.cg = cg;
              isHost = false;
         //The constructor of the server
         public MyUserInterface(ServerGame sg){
              this("Server");
              this.sg = sg;
              isHost = true;
         //The general constructor used both by client and server ..
         // it initializes the GUi components and add an actionListenr to the button
         public MyUserInterface(String str) {
              super(str);
              myTextField = new JTextField(2);
              te = new JTextArea();
              te.setPreferredSize(new Dimension(100,100));
              JButton okButton = new JButton("Ok");
              okButton.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e) {
                        try{
                             int a = Integer.parseInt(MyUserInterface.this.myTextField.getText());
                             System.out.println(a);   //used to control the flow of the program
                                  MyUserInterface.this.returnObject = new MyObject(a);
                             //sends the data
                             sendData();
                             //waiting for response...
                             getData();
                             catch(Exception ex){System.out.println("Error in the UI action command" +
                                                                ex.printStackTrace();}
              JPanel panel =  new JPanel(new FlowLayout());
              panel.add(okButton);
              panel.add(myTextField);
              panel.add(te);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              getContentPane().add(panel);
              pack();
              setVisible(true);
         protected MyObject getReturnObject() {
              return returnObject;
         public void sendData(){
              new Thread(new Runnable() {
                   @Override
                   public void run() { 
                        if (!isHost)cg.sentData(returnObject);    //using the Servers out and in methods
                        else sg.sentData(returnObject);                    //using the Clients out and in methods
                        System.out.println("data sending");
         public MyObject getData(){
              MyObject obj;
              System.out.println("Retrieveing Data");
              if (!isHost)obj = (MyObject)cg.getData();
              else obj = (MyObject)sg.getData();
              System.out.println(" data retrieved  = "+ obj.getInt());  //just to control how the code flows
              te.setText(obj.getInt()+"");       
              return obj;
         public static void main(String[] args) {
              *Initiating the Server
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        ServerGame sg = new ServerGame();
                        new MyUserInterface(sg);
              }).start();     
               * Initiating the Client
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        ClientGame cg = new ClientGame("192.168.178.21");   //<----in case you run my code
                                                                          //..don't forget to change to your
                        new MyUserInterface(cg);                              //ip
              }).start();
    import java.io.*;
    import java.net.*;
    public class ClientGame {
         String ipAddress;
         Socket clientSocket = null;
        ObjectOutputStream out = null;
        ObjectInputStream in = null;
         public ClientGame(String ipAddress) {
              this.ipAddress = ipAddress;
              try {
                   System.out.println("Connecting To Host");
                 clientSocket = new Socket(InetAddress.getByName(ipAddress),4444);
                System.out.println("Host Found ...Io initializaton");
                out = new ObjectOutputStream(clientSocket.getOutputStream());
                in = new ObjectInputStream(clientSocket.getInputStream());
            } catch (UnknownHostException e) {
                System.err.println("Don't know about host: taranis.");
                System.exit(1);
            } catch (IOException e) {
                System.err.println("Couldn't get I/O for the connection to: taranis.");
                System.exit(1);
         public Object getData(){
              Object fromServer = null ;
              do{
                 try {
                      fromServer = in.readObject();
                 catch(ClassNotFoundException ex){}
                  catch(IOException e){}
              }while(fromServer==null);
              return fromServer;        
         public void sentData(final Object obj){
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        try{
                             out.writeObject(obj);
                        catch(IOException e){}
              }).start();
         public void terminateConnection(){
              try{
                   out.close();
                   in.close();
                   clientSocket.close();
              catch (IOException e){}
    public class ServerGame {
         ServerSocket serverSocket;
         Socket clientSocket;
         ObjectOutputStream out = null;
        ObjectInputStream in = null;
         public ServerGame() {
              try{
                   serverSocket = new ServerSocket(4444);
                   clientSocket = serverSocket.accept();
                   out =  new ObjectOutputStream(clientSocket.getOutputStream());
                in = new ObjectInputStream(clientSocket.getInputStream());
              catch(IOException e){System.out.println("IOException in ServerGame");}
         public Object getData(){
              Object fromClient = null ;
              do{
                 try {
                      fromClient = in.readObject();
                 catch(ClassNotFoundException ex){}
                  catch(IOException e){}
              }while(fromClient==null);
             return fromClient;        
         public void sentData(final Object obj){
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        try{
                   out.writeObject(obj);
              catch(IOException e){}
              }).start();
         public void terminateConnection(){
              try{
                   out.close();
                   in.close();
                   clientSocket.close();
                   serverSocket.close();
              catch (IOException e){}
         public static void main(String[] args) {
              new ServerGame();
    import java.io.Serializable;
    * this is a test object
    * it has a String field and a value
    *  The string is always the same but the integer value is defined in the constructor
    public class MyObject implements Serializable{
         private static final long serialVersionUID = 1L;
         String str;
         int myInt;
         MyObject(int a){
              str = "A String";
              myInt = a;
         public int getInt(){
              return myInt;
    }

    Pitelk wrote:
    I believe that a good code example can teach you things ;that you would need many days of searching; in no timeSo lets write one small example.. Ill help a little, but you do most of the work.
    jverd approach is deffenetly the way to go.
    jverd wrote:
    * Write a very small, simple Swing program with an input area, an output area, and a button. When you click the button, what's in the input area gets copied over to the output area.This part is partially done.
    * Write a very small, simple client/server program without Swing. It should just send a couple of hardcoded messages back and forth.And this part is for you(Pitelk) to continue on. I cannot say that this is the best way. or that its good in any way. I do however like to write my client/server programs like this. And perhaps, and hopefully, Ill learn something new from this as well.
    This is how far I got in about 10-20min..
    package client;
    * To be added;
    * A connect method. That connects the client to the server and
    * opens up both the receive and transmit streams. After doing that
    * the an instance of the ServerListener class should be made.
    * Also an disconnect method could be usable. But thats a later part.
    public class TestClass1 {
    package utils;
    import java.io.ObjectInputStream;
    import client.TestClass1;
    * This class is meant to be listening to all responses given from
    * the server to the client. After a have received data from the
    * server. It should be forwarded to the client, in this case
    * TestClass1.
    public class ServerListener implements Runnable {
         public ServerListener(ObjectInputStream in, TestClass1 tc) {
         @Override
         public void run() {
              while(true) {
    package server;
    import java.io.ObjectOutputStream;
    import java.net.Socket;
    import java.util.ArrayList;
    import java.util.List;
    * This class should handle all data sent to the server from the clients.
    class Server implements Runnable {
         private static List<ObjectOutputStream> outStreams = new ArrayList<ObjectOutputStream>();
         private Socket client = null;
         public Server(Socket client) {
              this.client = client;
         @Override
         public void run() {
              while(true) {
    * The meaning of this class is to listen for clients trying to connect
    * to the server. Once connection is achieved a new thread for that client
    * should be made to listen for data sent by the client to the server.
    public class ChatServer implements Runnable {
         @Override
         public void run() {
              while(true) {
    package utils;
    import java.io.Serializable;
    @SuppressWarnings("serial")
    public class MyObject implements Serializable {
         private String mssg;
         private String clientID;
         private String clientName;
         public MyObject(String mssg, String clientID, String clientName) {
              this.mssg = mssg;
              this.clientID = clientID;
              this.clientName = clientName;
         //Generate getters and setters..
    }Continue on this, and when you get into problems etc post them. Also show with a small regular basis how far you have gotten with each class or it might be seen as you have lost intresst and then this thread is dead.
    EDIT: I should probably also say that Im not more than a java novice, at the verry most. So I cannot guarantee that I alone will be able to solve all the problems that might occure during this. But Im gonna try and help with the future problems that may(most likely will) occure atleast(Trying to reserve my self incase of misserable failiure from me in this attempt).
    Edited by: prigas on Jul 7, 2008 1:47 AM

Maybe you are looking for

  • Video iPod Shows 1777 GB, Shows it's Full of "Other"...

    iTunes shows it has music on board, but when I eject and try to see the music. There's nothing there. Anyone seen this issue before?

  • Row to Column Conversion Question

    Hi All,            Could you please help on this sql query statement: SELECT BENEFIT FROM TEST_T ; BENEFIT QO,1G,1U,1W Out Put Needed like this BENEFIT QO 1G 1U 1W Thanks,

  • FAQ's on PROXIES

    Hi Folks,    I am preparing for interview so can anyone provide me the question on PROXIES ( client and server ABAP), SOAP, HTTP and JMS adapters, or any questions relating to scenarios involving these adapters. (like SOAP TO JDBC, proxy to file and

  • CFDOCUMENT with Images = Huge File

    I've been looking through the forum and google and can't find a straight answer. Has Adobe responded to the issue? My PDF is 10x that of the image. I know there are alternatives to CFDOCUMENT, I know the PDF's can be optimized out of CF, but why isn'

  • I did the itunes update on my computer and how I cant get Itunes to work.

    I am upset, I did the typical update that I tunes gives you and now I can't get it to work at all. It says I need permission to use it, or that the moible system is not working which I am not sure what that means at all.