Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Failed Client-Socket Communication
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


Advertisement
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 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
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
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
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
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
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
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
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
 

 

 

DMCA.com