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 CommunicationFailed 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 ProcedureFailed 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 SessionBeanLookup
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
digital communication systemdigital
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 CommunicationData 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 stateunit 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 CommunicationInter 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
Eclipse-launch failed binaries not foundEclipse-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
applet servlet communication - Appletapplet 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 JavaInterthread
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 - StrutsInter 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
Backup Failed Mysqldump Got Errno 28 On WriteBackup
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 libraryEclipse 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 missingvalidation
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 missingvalidation
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
Java Serial Communication - IDE QuestionsJava 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