Home Tutorialhelp Comment java tcp client server program

 
 

Comment

bhanks
java tcp client server program,
October 27, 2010 at 9:11 AM

i've not been able to run the following program:

import java.io.*;
import java.net.*;

public class Client {
public static void main(String[] args) throws Exception {
String sentence;
String modifiedSentence;

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("Ju-PC", 6789);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

while((modifiedSentence = inFromServer.readLine()) != null){
if (modifiedSentence.equals("exit"))
break;

System.out.println("FROM SERVER: " + modifiedSentence);

sentence = inFromUser.readLine();

if (inFromUser != null) {
outToServer.writeBytes(sentence + '\n');
if(sentence.equals("exit"))
break;
}


}

clientSocket.close();
inFromUser.close();
outToServer.close();
inFromServer.close();
}
}

import java.io.*;
import java.net.*;

public class Server {
public static void main(String[] args) throws Exception {
String clientSentence;
String sentence;

ServerSocket welcomeSocket = new ServerSocket(6789);
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
BufferedReader serverInput = new BufferedReader(new InputStreamReader(System.in));

sentence = serverInput.readLine();
outToClient.writeBytes(sentence + '\n');

while((clientSentence = inFromClient.readLine()) != null) {

if(clientSentence.equals("exit"))
break;

System.out.println("FROM CLIENT: " + clientSentence);

if (serverInput != null) {
sentence = serverInput.readLine();
outToClient.writeBytes(sentence + '\n');
if (sentence.equals("exit"))
break;
}
}

welcomeSocket.close();
connectionSocket.close();
inFromClient.close();
outToClient.close();
serverInput.close();
}

View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Java Beginners

tcp client server communication
tcp client server communication  i am not been able to find the error in the program server: import java.io.*; import java.net.*; public class Server { public static void main(String[] args) throws Exception 

Java Beginners

MultiClient-server tcp-ip with GUI in java
MultiClient-server tcp-ip with GUI in java  i wanna MultiClient-server tcp-ip with GUI in java 

Java Beginners

MultiClient-server tcp-ip with GUI in java
MultiClient-server tcp-ip with GUI in java  i wanna MultiClient-server tcp-ip with GUI in java 

Java Beginners

Client Server Java app
Client Server Java app  I developed a client server based java networking Instant Messaging app. The client program is needed to be run on the client computer whereas the server program is on server computer. This works in my 

Java Beginners

proxy server and client using java - Java Beginners
proxy server and client using java  how to write program in java for proxy server and client 

Java Beginners

File transfer from client to server - Java Beginners
File transfer from client to server  hi,, I've been trying to make an application where the user select a file using JFileChooser and then the program directly send it to the server using client/server sockets, I've tried 

Java Server Faces Questions

server with two port - Java Server Faces Questions
server with two port  Hello, want to write two port server socket program using Java, (i.e. single server program which is listening on two ports (say 3122 and 3133) simultaneously. In this program when two different clients 

Java Beginners

What is Java Client Socket?
What is Java Client Socket?  Hi, What is client socket in Java.... The socket that make connectivity with socket client and with a socket server... socket connections. To get connection in client socket in java used the class 

Web Services

Difference between Web Server and Application Server
the Application server allows business logic to client through various protocols like HTTP, TCP-IP etc. Web Server generates a response generally in HTML... response generation to some other program. An application server are designed 

Java Server Faces Questions

download program by java - Java Server Faces Questions
download program by java  I have to complete excercise about java as create a program download like flashget or idm, i have no idiea about this, please share me source code to refer, thanks 

General

RMI Client And RMI Server Implementation
RMI Client And RMI Server Implementation  ... comprises of the two separate programs, a server and a client. A typical server... application provides the mechanism by which the server and the client communicate 

Java Server Faces Questions

program code - Java Server Faces Questions
program code  hai i am meyis i need a jsp program code for date generation.(mssql-back end) Fields are fromdate and todate both field are datetime datatype. Button:-save,cancel,exit todate is taken from the server.fromdate 

Java Magazine Questions

Server calling of .exe file in the client
Server calling of .exe file in the client   I have a requirement with java webapplication. We are using jboss as appserver on Linux machine. How can I call a .exe file from client machine? I want to run .exe from webpage like 

Swing AWT

java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... class client extends JFrame { clientreceive cr; JPanel p; public void init 

Swing AWT

java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... class client extends JFrame { clientreceive cr; JPanel p; public void init 

Swing AWT

java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... class client extends JFrame { clientreceive cr; JPanel p; public void init 

Swing AWT

java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same... a client server program to play a video file, when I run both client and server... class client extends JFrame { clientreceive cr; JPanel p; public void init 

Java Server Faces Questions

Java socket Programming - Java Server Faces Questions
Java socket Programming  I want to create a web server. How do I retrieve URL sent by client and how do server responds to the specific URL requested by the client 

Java Server Faces Questions

Synchronization probleam - Java Server Faces Questions
(); frame.setTitle("Server Program"); WindowListener l = new WindowAdapter...Synchronization probleam   Hi friends My java multithreading... implements Runnable { private Socket client; private JTextArea textArea 

Java Server Faces Questions

Synchronization probleam - Java Server Faces Questions
(); frame.setTitle("Server Program"); WindowListener l = new WindowAdapter... Socket client; private JTextArea textArea; ClientWorker(Socket client, JTextArea textArea) { this.client = client; this.textArea = textArea 

General

Application Server : Java Glossary
Application Server : Java Glossary       An Application server is a server side program that is used to provide service to the client simply by recieving request and sending back 

Java Beginners

Java FTP Client Example
Java FTP Client Example  How to write Java FTP Client Example code? Thanks   Hi, Here is the example code of simple FTP client in Java which downloads image from server FTP Download file example. Thanks 

Java Beginners

java program
java program  write a program to create server and client such that server receives data from client using BuuferedReader and sends reply to client using PrintStream 

General

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 

XML Questions

java
java  tcp/ip client and server programe 

Java Beginners

Java FTP Client
Java FTP Client  What all Java FTP Client available to the Java programmers? Is there any Free FTP Client Library? Thanks   Hi, Apache... Client libraries which can be used to connect to the FTP server for: Uploading 

Java Beginners

Create text file at client's directory from server.
Create text file at client's directory from server.  Need java code to create text file at client's directory from server..... Please Help 

Java Code Examples

UDP Client in Java
UDP Client in Java     ... or messages for UDP server by the UDP client. For this process you must require..., then you send messages to UDP server. The sending process has been defined just  

Java Interview Questions

thin-client project - Java Interview Questions
thin-client project  what is thin-client project??? Plz help me  Hi Friend, Please visit the following link: http://www.roseindia.net/linux/linux-thin-client-terminals.shtml Hope that it will be helpful for you 

Java Server Faces Questions

array - Java Server Faces Questions
array  Write a program that read 15 integers between 0 and 6 and a method to search, displays and returns the number that has the highest occurrence. Prompt the user if the number is not within this range 

Java Server Faces Questions

JSP - Java Server Faces Questions
JSP  How i can create a directory from the JSP program ?  Hi friend, Code to Create a directory using JSP : For more information on JSP visit to : http://www.roseindia.net/jsp/ Thanks 

WebSevices Questions

Client's Data with Axis2 and Java
client's data? First of all back-end will be build in Java(will try to implement some... worked with Eclipse(duh) there is very nice feature of generating server/client...Client's Data with Axis2 and Java  Hello everyone, I am studying 

Java Server Faces Questions

jsp - Java Server Faces Questions
jsp  hi u didnt get my question properly. i need to create directory where i can locate the program in the system in any system(i.e for one system tomcat is in C drive but in another system tomcat is in D: drive).I hope u 

Java Beginners

Hi i want java code that diaplays server scren at the client side
Hi i want java code that diaplays server scren at the client side  Hi I'm Shivaprasad i want java socket code that shows the server side screen when client gets connected with the server. Please help me   Please visit 

Java Beginners

program in java
program in java  a program to develop a client, server application to satisfy the requests from multiple clients 

Java Beginners

program in java
program in java  a program to develop a client, server application to satisfy the requests from multiple clients 

Java Server Faces Questions

Java and socket - Java Server Faces Questions
Java and socket  Pls pals help me out coz i try to create a chating application where multiple client can interact with a server, i have tried by making the server multithreaded it only allows multiple connections but and give 

Java Server Faces Questions

java struts validation - Java Server Faces Questions
java struts validation  i m unable to execute a validation page by struts . so please write u program and create a rar/jar file having all program with procedure and sand me . pls........ i m using bea weblogic 8.1 . my mail 

Java Server Faces Questions

Multicast under UDP(client server application)
Multicast under UDP(client server application)   UDP is used...: In this project, you will write two classes RMulticastServer (called server in the following) and RMulticastClient (called client in the following) in Java 

Java Server Faces Questions

java 2 - Java Server Faces Questions
java 2  1) a) Write a pseudo code algorithm to pick the 1st element... and partitioning) to Java. It should be able to execute any set of data. Note:- You should provide the test data and the results of your program. (c) Modify your program 

Servlets

Web Server
program. While talking about Java language then a web server is a server...; A web server is the combination of computer and the program installed on it. Web server interacts with the client through a web browser. It delivers the web 

Java Server Faces Questions

java programme - Java Server Faces Questions
java programme  Write a complete program, which prints all Fibonacci numbers that are less than 1600.  Hi Friend, Try the following code: public class FibonnaciSeries { public static void main(String[] args 

Java Code Examples

Multicast Client in Java
UDP Multicast Client in Java   ... server.  Here is the code of program: import ... to send and receive the IP packet or message by multicast client. Here, we provide 

Java Server Faces Questions

java do wile - Java Server Faces Questions
java do wile  Write a program that asks the user to enter two words. The program then prints out both words on one line. The words will be separated by dots so that the total line length is 40. If your first word was turtle 

Java Server Faces Questions

Java Server - Java Server Faces Questions
Java Server login Session  I have site in which user logs in and uses the services... the session should be closed so i used the java script, In java script i used... the toolbar in the java script through window.open 

Java Server Faces Questions

about threading in java - Java Server Faces Questions
about threading in java  Hello Sir how can i write a program using threads and which need to check and compare the system date and time every day at certain time(eg:12 o clock in noon).. based on this comperision of time i 

Java Server Faces Questions

Java - Java Server Faces Questions
Java  I want complete details about Java Server Faces.  Hi friend, Java Server Faces is also called JSF. JavaServer Faces is a new framework for building Web applications using JSP and Servlet. Java Server 

General

Java UDP
to server and server to client. A datagram is an independent, self-contained... Java UDP       TCP and UDP are transport protocols used for communication between computers. UDP 

Java Server Faces Questions

java - Java Server Faces Questions
java  Java Server Faces Quedtions  Hi friend, http://www.roseindia.net/interviewquestions/jsf/ http://www.roseindia.net/interviewquestions/jsf/JSF-interview-questions.shtml Thanks 

Java Server Faces Questions

java - Java Server Faces Questions
Java reverse string recursively  Hi all, Please give me an example of java reverse string recursively 

Java Server Faces Questions

J2ME HELP - Java Server Faces Questions
xml file from any one server in internet 2. Parsing that xml file. 3... code for this mobile application program I am using File Connection object for receving the xml file from server kXML parser is used for parsing the xml 

Java Server Faces Questions

java server pages - Java Server Faces Questions
java server pages  code for jsp login page if user forgot password reminding password with hint question.the table login is created in database  Hi Friend, Try the following code: 1)email.jsp: Enter Email 

Java Server Faces Questions

file uploading - Java Server Faces Questions
questions .But its not working for file uploading . U ask me to send the entire code. This program is working for lan but its not working for server pls tell me where is the problem 

Java Interview Questions

java - Java Interview Questions
java  Write a Multi-user chat server and client 

Java Beginners

WAS server configuration from JAVA program
WAS server configuration from JAVA program  How to get web sphere server status like heap,connection pool properties,stall counts etc. from a java applciation 

Java Code Examples

Sending and receiving information to the UDP Client in Java
Sending and receiving information to the UDP Client in Java... will provide send and receive information by the UDP client in Java. UDP client... UDP server. Description of program: When you will run the program then appears 

Java Beginners

program for chat - Java Beginners
program for chat  please provide code for fallowing 1)Write a java program Multi-user chat server and client 

Java Server Faces Questions

java - Java Server Faces Questions
java  hw can i access the ip addresses in a network thanx in advance  Hi friend, Read for more information. http://www.roseindia.net/java/network/index.shtml Thanks 

Java Server Faces Questions

java - Java Server Faces Questions
java  hi i need a sample code for generating sms alerts at the time of online registration which takes data from database and generate sms alert to customer after success full registration in java 

Java Server Faces Questions

jsp - Java Server Faces Questions
jsp  Thanks for answering previous questions . Q)I need a code to draw line graph in jsp Thank u Happy new year  Hi friend, Code to help in solving the problem : Thanks 

Java Server Faces Questions

jsp tag handler - Java Server Faces Questions
jsp tag handler  How to write tag handler program? what are the classes, methods use? can any explain me step by step. tld file tag handler file jsp file 

Java Server Faces Questions

abt jmeter - Java Server Faces Questions
abt jmeter  how to use jmeter for testing the program?   Hi friend, For using jmeter for testing visit to : http://www.roseindia.net/jmeter/ http://www.roseindia.net/jmeter/using-jmeter.shtml Thanks 

Java Code Examples

UDP Server in Java
UDP Server in Java     ... of UDP server. This section provides you the brief description and program... a reliable communication has options of using either TCP or a program based 

Ajax Questions

Java Client Application
Java Client Application  Java Client Application 

Java Server Faces Questions

java - Java Server Faces Questions
java  how to write the code for a schedular in java plz help in this i will be thank ful to u   hi friend, import java.util.*; public class SchedularTest { private final Timer timer = new Timer(); int 

Java Server Faces Questions

message interruption - Java Server Faces Questions
) will be repeated. To resend the data click ok. " I want my program 

Java Server Faces Questions

source code - Java Server Faces Questions
source code  hi deepak i need a program's source code in javascript which will response to mouse event. with description of onmouseout nd onmouseover... waiting 4 ur reply   Hi friend, Code for onmouseout nd 

Java Server Faces Questions

JSF Search - Java Server Faces Questions
friend, I think, you want to make search program using jsf technologies. I 

Java Beginners

web service client
web service client  i have implement web service client in netbeans and it work will using wsdl but know i want to Develop a webserivce (or a Java RMI server/client) for one of the e-services but i do not know the wsdl link how 

Java Beginners

java program 32
java program 32  Write a java program to create server and clint such that server receives data from clint using BufferedReader and send reply to client using PrintStream 

Java Server Faces Questions

java - Java Server Faces Questions
 

Java Server Faces Questions

java - Java Server Faces Questions
 

Java Server Faces Questions

java - Java Server Faces Questions
 

Java Server Faces Questions

java - Java Server Faces Questions
 

Java Server Faces Questions

Java - Java Server Faces Questions
 

Java Server Faces Questions

java - Java Server Faces Questions
 

Java Server Faces Questions

java - Java Server Faces Questions
 

General

Datagram in network environment
;    In a network environment the client and the server communicate with each-other by reliable channel like TCP socket which have dedicated point-to-point channel between client and server. All data sent over 

Java Beginners

Java Client Application example
Java Client Application example  Java Client Application example 

HTML Questions

Java HTML Client Application
Java HTML Client Application  Java HTML Client Application 

Java Server Faces Questions

apache tomcat server - Java Server Faces Questions
procedure.  Hi Friend, To install the tomcat server,please visit the following link: http://www.roseindia.net/web-application-server/tomcat/install 

Java Server Faces Questions

WebServer - Java Server Faces Questions
WebServer  What is WebServer? Do i need one for the Java programming... server Web container is nothing but a folder where a web... are stored in seperate folders. Web server is known as a server which 

Java Server Faces Questions

tomcat server - Java Server Faces Questions
server error */ Jul 28, 2008 10:42:07 PM...) at org.apache.coyote.tomcat5.CoyoteConnector.initialize(CoyoteConnector. java:1326...) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39 

Java Server Faces Questions

proxy - Java Server Faces Questions
proxy  thank u deepak123 but i`m realy looking forwods for strong proxy server or web-server, so pleas my frainds.. if there's any chans help me by sending it to my email.becuse i need alot of time to laern how to loade 

Java Interview Questions

OC4J Server - Java Interview Questions
OC4J Server  How to run web application in eclipse3.0 in debug mode using OC4J Server? Please let me know asap 

Java Server Faces Questions

mysql server connectivity - Java Server Faces Questions
mysql server connectivity  hello friends, my question is that i m not able to connect jsp, servlet with sql 2000. i know we have to do some changes in administrative tools in control pannel but after click 

Java Beginners

multiple choice questions program
multiple choice questions program  how can i implement the program to store 10 multiple choice questions in one class to develop a oneline quiz with using java language 

Java Beginners

multiple choice questions program
multiple choice questions program  how can i implement the program to store 10 multiple choice questions in one class to develop a oneline quiz with using java language 

JSP Interview Questions

java, - JSP-Interview Questions
. It is used by Client to send request to the server. It contain the path (domain...java,  hi.. define URI? wht is difference b/w URL and URI wht... that defines the route to a file on an Internet server (Web server, FTP server 

Java Beginners

Small program code - Java Beginners
Small program code  Develop the echo server and the echo client program that display whatever is typed in the server on to the client 

Java Server Faces Questions

JSF - Java Server Faces Questions
JSF  How to upload a image on server through JSF? Could anybody help me?  Hi friend, For upload a image in JSF visit to : http://www.roseindia.net/jsf/apache-myfaces-tomahawk/tomahawk_inputFileUpload_tag.shtml 

Java Server Faces Questions

sms - Java Server Faces Questions
sms  hello .... can any body tell me how to send sms from pc to mobile using java ..an if possible please give me the code in jsp..... my email id is:bharachaitanya@yahoo.co.in 

Java Server Faces Questions

thread inside other thread - Java Server Faces Questions
thread inside other thread  Expert:I Hello, can you help me please: I want to connect client and server that the client send three times msg1 and when he send msg2 he will connect with another server by create new thread 

Java Server Faces Questions

JSF - Java Server Faces Questions
server and Oracle.By just giving the information regarding the tags will not help 

JSP Servlet Questions

Tomcat Server
Tomcat Server  Why my tomcat server installation stop at using:jvm c:\program files\java\jdk 1.6.0\bin\client\jvm.dll. Even though i trying to install several times. please help me....   Installing Tomcat Server 

Java Server Faces Questions

j2ee - Java Server Faces Questions
in work. Jus i saw your answer. Java is the flexible language in the language family... *******////index.jsp////////////****** welcome in java world.../////*******(to get value from the session) Welcome in java expert world 

Java Server Faces Questions

jsf - Java Server Faces Questions
server javax.faces.CONFIG_FILES /WEB-INF/faces 

Java Interview Questions

java program - Java Interview Questions
java program  i want information of locks in java ? 1.what is a class lock? 2.what is method lock? 3.what is a object lock? i want some code.../java/thread/SynchronizedThreads.shtml Thanks 

Java Server Faces Questions

js - Java Server Faces Questions
js  How to capture the IP address or URL text of the status bar using java script in Internet Explorer? Can any one help us? Thanks in advance for all your valuable time.  Hi friend, 1. First, make a javaScript 

Java Server Faces Questions

JSF - Java Server Faces Questions
JSF  1.Student has to register for the course. It contains User name Password Confirm password First Name Last name Course : java, struts, JSP (these are radio buttons 

Advertisements Advertisements
 

 

 

DMCA.com