Failed Client-Socket Communication

Ads

 
 

Share on Google+Share on Google+

Suzanne T
Failed Client-Socket Communication
0 Answer(s)      6 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]

Ads
View Answers
Ads









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 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Tutorials   
Java Spring Hibernate Struts Training What type of programming language is Java? How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017

Ads

 
Advertisement null

Ads