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 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 Tutorials/Questions & Answers:
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
Advertisements
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
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
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
Failed to Call Procedure
Failed to Call Procedure  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sum(case when c.result = '1' then 1 else 0 end ) as Pass_total, sum
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
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
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
Data over Voice Communication
Data over Voice Communication  I just Want to know that Data Over Voice communication is possible in India or Not, If not then Why. and If Yes then Why Please anyone give the answer
unit elasticsearch.service entered failed state
unit elasticsearch.service entered failed state  Hi, I am working on elastic search and suddenly it stopped working with following error: unit elasticsearch.service entered failed state How to resolve this? Thanks   
open() /etc/nginx/nginx.conf failed
-VirtualBox nginx[2880]: nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2...: configuration file /etc/nginx/nginx.conf test failed Apr 04 17:29:34 bugs-VirtualBox...:29:34 bugs-VirtualBox systemd[1]: nginx.service: Failed with result 'exit-code
open() /etc/nginx/nginx.conf failed
-VirtualBox nginx[2880]: nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2...: configuration file /etc/nginx/nginx.conf test failed Apr 04 17:29:34 bugs-VirtualBox...:29:34 bugs-VirtualBox systemd[1]: nginx.service: Failed with result 'exit-code
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
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
MySQL server PID file could not be found! [FAILED]
MySQL server PID file could not be found! [FAILED]  MySQL server PID file could not be found! [FAILED
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
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
ModuleNotFoundError: No module named 'luxx_communication'
ModuleNotFoundError: No module named 'luxx_communication'  Hi, My... named 'luxx_communication' How to remove the ModuleNotFoundError: No module named 'luxx_communication' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pumpwood-communication'
ModuleNotFoundError: No module named 'pumpwood-communication'  Hi...: No module named 'pumpwood-communication' How to remove the ModuleNotFoundError: No module named 'pumpwood-communication' error? Thanks   Hi
ModuleNotFoundError: No module named 'pumpwood-communication'
ModuleNotFoundError: No module named 'pumpwood-communication'  Hi...: No module named 'pumpwood-communication' How to remove the ModuleNotFoundError: No module named 'pumpwood-communication' error? Thanks   Hi
ModuleNotFoundError: No module named 'gaia-communication'
ModuleNotFoundError: No module named 'gaia-communication'  Hi, My... named 'gaia-communication' How to remove the ModuleNotFoundError: No module named 'gaia-communication' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'gaia-communication'
ModuleNotFoundError: No module named 'gaia-communication'  Hi, My... named 'gaia-communication' How to remove the ModuleNotFoundError: No module named 'gaia-communication' error? Thanks   Hi, In your
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 :ADS_TO_REPLACE_1
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
Version of com.michaelpardo>materialdesignicons-communication dependency
List of Version of com.michaelpardo>materialdesignicons-communication dependency
ModuleNotFoundError: No module named 'pytest-failed-to-verify'
ModuleNotFoundError: No module named 'pytest-failed-to-verify'  Hi...: No module named 'pytest-failed-to-verify' How to remove the ModuleNotFoundError: No module named 'pytest-failed-to-verify' error? Thanks   
servlet to applet communication
(servletConnection.getInputStream()); g.drawString("Applet Servlet Communication",50,50); String str
LOGIN FAILED", $_SESSION['login fail']='0',}?>
LOGIN FAILED", $_SESSION['login fail']='0',}?>  please correct my error guys
Backup Failed Mysqldump Got Errno 28 On Write
Backup Failed Mysqldump Got Errno 28 On Write  Hi, While taking the backup of database I got following error: Backup Failed Mysqldump Got Errno 28 On Write How to resolve the issue? Thanks   Hi, This error comes
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
Eclipse juno failed to load the jni shared library
Eclipse juno failed to load the jni shared library  Hi, I have downloaded the 64 BIT version of Eclipse juno "eclipse-jee-juno-SR2-win32-x86_64.zip... the error "Eclipse juno failed to load the jni shared library". Let's know what
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
validation failed 1 mapping type is missing
validation failed 1 mapping type is missing  Hi, I am creating an index in elastic search but following command: PUT bookstore/_mapping...": true } } } But kibana is throwing error: validation failed 1 mapping type
validation failed 1 mapping type is missing
validation failed 1 mapping type is missing  Hi, I am creating an index in elastic search but following command: PUT bookstore/_mapping...": true } } } But kibana is throwing error: validation failed 1 mapping type
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
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
ModuleNotFoundError: No module named 'odoo10-addon-pos-backend-communication'
ModuleNotFoundError: No module named 'odoo10-addon-pos-backend-communication...: ModuleNotFoundError: No module named 'odoo10-addon-pos-backend-communication' How...-communication' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-vat-statement-communication'
-communication'  Hi, My Python program is throwing following error...-communication' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-vat-statement-communication' error? Thanks   Hi
ModuleNotFoundError: No module named 'computer_communication_framework'
ModuleNotFoundError: No module named 'computer_communication_framework' ...: ModuleNotFoundError: No module named 'computer_communication_framework' How to remove the ModuleNotFoundError: No module named 'computer_communication_framework'
ModuleNotFoundError: No module named 'odoo10-addon-l10n-it-invoices-data-communication'
-communication'  Hi, My Python program is throwing following error...-communication' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-l10n-it-invoices-data-communication' error? Thanks   Hi
ModuleNotFoundError: No module named 'odoo10-addon-pos-backend-communication'
ModuleNotFoundError: No module named 'odoo10-addon-pos-backend-communication...: ModuleNotFoundError: No module named 'odoo10-addon-pos-backend-communication' How...-communication' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'odoo10-addon-pos-backend-communication'
ModuleNotFoundError: No module named 'odoo10-addon-pos-backend-communication...: ModuleNotFoundError: No module named 'odoo10-addon-pos-backend-communication' How...-communication' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-invoices-data-communication'
-communication'  Hi, My Python program is throwing following error...-communication' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-invoices-data-communication' error? Thanks   Hi
ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-invoices-data-communication'
-communication'  Hi, My Python program is throwing following error...-communication' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-invoices-data-communication' error? Thanks   Hi
ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-invoices-data-communication'
-communication'  Hi, My Python program is throwing following error...-communication' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-l10n-it-invoices-data-communication' error? Thanks   Hi

Ads