Home Answers Viewqa Java-Beginners Failed Client-Socket Communication

 
 


Suzanne T
Failed Client-Socket Communication
0 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners

I hve written a server program & a client program. The server is supposed to echo watever is typed in the client. I hve to get 16 values to be echoed. I hve created a string and all the values are added to this string. When I pass the string to the server, it doesn get echoed by the server. In fact server hangs @ tat part after establishing connection with the client. I am at my wits end!Can someone run the code for me & explain why it hangs when its supposed to echo the value in server? I hve changed my code 7 times already still I can't understand why it hangs, tis is really a desperate call, stuck with tis 4 4 days alreay.

SERVER PROGRAM:

[code] import java.io.*; import java.net.*; import java.util.*;

public class AS3{ public static void main(String[] args ){ int i = 1; try{ ServerSocket s = new ServerSocket(9001);

         for (;;){
             Socket incoming = s.accept( );
             System.out.println("Spawning " + i);
             new RealEchoHandler(incoming, i).start();
             i++;
         }
    } catch (Exception e){ System.out.println(e); }
}

}

class RealEchoHandler extends Thread{ DataInputStream in; DataOutputStream out; private Socket incoming; private int counter;

public RealEchoHandler(Socket i, int c){
    incoming = i;
    counter = c;
}

public void run(){
    try {

        in = new DataInputStream(incoming.getInputStream());
        out = new DataOutputStream(incoming.getOutputStream());

        boolean done = false;
        String str="";
        out.writeUTF("Connected!\n");
        out.flush();
        while (!done){
            out.writeUTF(">");
            out.flush();
            str = in.readUTF();
            System.out.println(in+":"+str);
            if (str == null)
                done = true;
            else{
                out.writeUTF("Echo (" + counter + "): " + str+"\n");
                out.flush();
            }
        }

        incoming.close();
     } catch (Exception e){
         System.out.println(e);
     }
}

}[/code]

CLIENT: [code] import java.io.*; import java.net.*; import java.util.*; class Client3{ public static void main(String[] args) { String store=""; String clientCar=""; String clientBranch=""; String clientDriver=""; String clientPasswd="";

    DataOutputStream out;
    DataInputStream in;
    try {
        Socket t = new Socket("127.0.0.1", 9001);

        in = new DataInputStream(t.getInputStream());
        out = new DataOutputStream(t.getOutputStream());
        BufferedReader br = new BufferedReader
                 (new InputStreamReader(System.in));
        boolean more = true;
        System.out.println(in.readUTF());
        while (more) {
            clientCar = in.readUTF();
            clientBranch = in.readUTF();
            clientDriver = in.readUTF();
            clientPasswd = in.readUTF();
            store = store + clientCar+clientBranch+clientDriver+clientPasswd;

            out.flush();
            store = in.readUTF();
            if (store == null)
                more = false;
            else
                out.writeUTF(store + "\n");
        }

     } catch(IOException e){
            System.out.println("Error" + e);
     }
     System.out.println(store);
 }

} [/code]

View Answers









Related Pages:
Failed Client-Socket Communication
Failed Client-Socket Communication  I hve written a server program & a client program. The server is supposed to echo watever is typed in the client. I hve to get 16 values to be echoed. I hve created a string and all
What is Java Client Socket?
, The client socket is basic communication interface between networked computers. The socket that make connectivity with socket client and with a socket server...What is Java Client Socket?  Hi, What is client socket in Java
Client Socket Information
Client Socket Information       In this section, you will learn how to get client socket information. This is a very simple program of java network. Here, we have
Access URL Failed!?
Access URL Failed!?  Hi, May i know how to convert my domain name into IP address? becuase i working on J2ME but don't know why the my application unable to access the URL. "connector.open("http://886089.com/datetime.asp")". I
Lookup failed in SessionBean
Lookup failed in SessionBean  Hi. I've downloaded session bean example which invokes session beans. File was named example3. So I wanted to make this servlet in NetBeans so I copied .java files, index.jsp and web.xml into proper
Communication Portal
Communication Portal       A communication interface desinged with Web 2.0 technology, mission is to help peolpe communicate easily over a comfortable web interface Read full Description
Communication Tube
Communication Tube       Communication Tube - web messenger chat client for the popular IM (instant messaging) networks: ICQ , MSN Messenger, Google Talk (GTalk) , IRC Read full
Interthread Communication
Inter-Thread Communication   ... communication among threads which reduces the CPU?s idle time i.e. A process where...; This technique is known as Interthread communication which is implemented by some
Communication Effectiveness in Outsourcing, Communication Techiques in Outsourcing
Communication Effectiveness in Outsourcing  Introduction A good part of the communication in outsourcing relationships is achieved... the specifics of the work, and also the client learns about the techniques
java.lang.RuntimeException: Failed to register user. - MobileApplications
java.lang.RuntimeException: Failed to register user.  Hi Mr.Deepak i... this java.lang.RuntimeException: Failed to register user...] com.mas.distribution.RegisterUserServlet::doGet 83: Failed to create the user
Eclipse-launch failed binaries not found
Eclipse-launch failed binaries not found  I recently downloaded eclipse(eclipse-cpp-europa-winter-win32) to work on c++. I don't know how to launch.... "LAUNCH FAILED NO BINARIES". Can anyone please explain me what's going on or problem
FAILED TO INSERT DATA FROM FUNCTION();
FAILED TO INSERT DATA FROM FUNCTION();  HELLO, I HAVE A PROBLEM TO INSERT DATA FROM OUTPUT FROM FUNCTION()... I WANT TO STORE THE OUTPUT IN DATABASE, BUT FAILED TO INSERT... before this.... ......................... function
digital communication system
digital communication system  A digital communication system capable of interconnecting, a large number of computers, terminals and other peripheral devices within a limited geographical area is called- a) LAN, B) WAN, C
Inter Thread Communication
Inter Thread Communication  what is inter thread communication?   hi friend, Inter thread communication is a process of communication between two threads. In this process, a thread outside the critical section is tried
applet servlet communication - Applet
applet servlet communication  Can anybody tell me applet - servlet communication by creating a webproject in eclipse. I am creating a web...()); g.drawString("Applet Servlet Communication",50,50); String str = new String(); str
Interthread Communication in Java
Interthread Communication in Java As you know about producer-consumer problem... wasting of cycle or polling, interthread communication is a good way.  Given below some function helpful in interthread communication : Methods
Inter Server Communication - Struts
Inter Server Communication   Hi In my project I am using Struts2.0 ,I have 2 server one is web-logic server and another is Tomcat server. In web-logic server , there is link to call tomcat server for call struts application
servlet to applet communication
(servletConnection.getInputStream()); g.drawString("Applet Servlet Communication",50,50); String str
tcp client server communication
tcp client server communication  i am not been able to find the error... ServerSocket(6787); Socket connectionSocket = welcomeSocket.accept...")) break; System.out.println("FROM CLIENT: " + clientSentence
Interthread communication
Interthread communication   ... communication among threads which reduces the CPU?s idle time i.e. A process where...; This technique is known as Interthread communication which is implemented by some
problem with executing JSF file(Build failed)
problem with executing JSF file(Build failed)  *while executing below... application at context path /JSFProject3 but context failed to start /root... deployed. BUILD FAILED (total time: 9 seconds)*** Please any one give me solution
Java Serial Communication - IDE Questions
Java Serial Communication  Does Netbeans support serial port communication for windows??? because netbeans doesnt support javax.comm package . I tried my program with notepad for rxtx. It worked properly & same with netbeans
What is the general flow of Hibernate communication with RDBMS?
What is the general flow of Hibernate communication with RDBMS?  Hi, What is the general flow of Hibernate communication with RDBMS? thanks
serial port communication using bluetooth in j2me
serial port communication using bluetooth in j2me   how to make serial port communication using bluetooth in j2me ? what r prerequisites
serial port communication using bluetooth in j2me
serial port communication using bluetooth in j2me   how to make serial port communication using bluetooth in j2me ? what r prerequisites
Communication Website Development
Communication Website Development We provide high quality Communication... team will help you in developing websites for Communication industry. We... for communication industry. A website is the virtual representation of a company
Need of Communication Management
Communication management is the systematic process by which any organization planned, implement, monitor or revision the all channels of communication for better output. It is the wide use of communication technology within
Communication: Marketing tools
Communication has become an inseparable part of modern life and the same is true for the survival of any business organization where communication... be a guarantee for its success if there is a gap of communication among its other
Failed to run Online Quiz Application in JSP - JSP-Interview Questions
Failed to run Online Quiz Application in JSP   Hi, I have been following your following link to run the online quiz application, but I failed to get the result screen and correct answer and score displayed in the web. Could
How to code in struts for 3 Failed Login attempts - Struts
How to code in struts for 3 Failed Login attempts  Hi, I require help. I am doing one application in struts where i have to incorporate the functionality like while log in if the user enters a wrong password for 3 times
SEVERE: Context [/hospital] startup failed due to previous errors
SEVERE: Context [/hospital] startup failed due to previous errors  Hi... org.apache.catalina.core.StandardContext start SEVERE: Context [/hospital] startup failed due to previous errors Jan... nam Thread-3] but has failed to stop it. This is very likely to create a memory
I got build failed when deploying enterprise application - EJB
I got build failed when deploying enterprise application  I created...% Deploying application in domain failed; Error loading deployment descriptors for module...(Deployment.java:160) ... 16 more BUILD FAILED (total time: 2 seconds)   
Outsourcing Communication Tips,Useful Cultural Tips in Offshore Outsourcing,Communication and Culture Tips
Communication and Culture Tips in Offshore Outsourcing Relationships... into difficulties due to communication problems. The trend is very prominent in both... communication arrangement? Or is it due to poor communication skills of the people
JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use.
JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use.  Deployment error: JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use. How can I solve
JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use.
JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use.  Deployment error: JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use. How can I solve it? How can I kill
JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use.
JBoss Application Server Start Failed. HTTP Connector port 8080 is already... Application Server Start Failed. HTTP Connector port 8080 is already in use. Deployment error: JBoss Application Server Start Failed. HTTP Connector port 8080

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.