Home Answers Viewqa Java-Beginners tcp client server communication

 
 


baanku
tcp client server communication
0 Answer(s)      2 years and 7 months ago
Posted in : Java Beginners

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 { String clientSentence; String sentence;

    ServerSocket welcomeSocket = new ServerSocket(6787);
    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();
}

}

client:

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("hostname", 6787); 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("Typed:"+sentence + '\n');
            if(sentence.equals("exit"))
                    break;
        }


    }

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

}

}

View Answers









Related Pages:
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
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
Java UDP
; TCP and UDP are transport protocols used for communication between computers. UDP... be used to send datagrams, using Datagram Sockets, to one another i.e. from client to server and server to client. A datagram is an independent, self-contained
Communication Effectiveness in Outsourcing, Communication Techiques in Outsourcing
of the project- whether it is software applications, product development, client-server...Communication Effectiveness in Outsourcing  Introduction A good part of the communication in outsourcing relationships is achieved
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
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
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
server client comms
server client comms  i am trying to return frame through server client comms anyone can help me about that i want to return a class to client side but my class defined in server side
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... Application server provides methods that client applications can call. Application
Client-Server Architecture
Client-Server Architecture       Client-server architecture can be considered...; and a client machine where server has some resources that can be shared by different
Most Common TCP Ports
or by programs executed by privileged users. Ports are used in the TCP [RFC793... is defined. This list specifies the port used by the server process as its contact port. Port Assignments for Common Ports: Port UDP TCP Definition 7 x x echo
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
applet servlet communication - Applet
communication by creating a webproject in eclipse. I am creating a web...()); g.drawString("Applet Servlet Communication",50,50); String str = new String(); str = (String)input.readObject(); g.drawString(" Message sent from server
servlet to applet communication
(servletConnection.getInputStream()); g.drawString("Applet Servlet Communication",50,50); String str... from server: " + str,50,100); input.close(); } catch( Exception e
Client-Server Architecture
Client-Server Architecture       Client-server architecture can be considered...; and a client machine where server has some resources that can be shared by different
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
how to connect client to server using Sockets
how to connect client to server using Sockets  how to connect client to server using Sockets
TCP socket
TCP socket  Respected sir/madam, Sir, i want to know about tcp sockets and udp datagrams which is used by mobile applications,shall i know how the chatting(sms) application can run by both people?how they enabled
TCP socket
TCP socket  Respected sir/madam, Sir, i want to know about tcp sockets and udp datagrams which is used by mobile applications,shall i know how the chatting(sms) application can run by both people?how they enabled
Rmi client
Rmi client  Sir i just created client and server following the RMI rule, its running properly in the localhost, when i am trying to run the program in the different machine its not working, i changed the ip also, when i copied
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
Server side validation vs client side validation
Server side validation vs client side validation  Can any one tell me... of Server side validation vs client side validation.   The client side validation runs in the browser where as server side validation runs on server
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
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
Application Server and Web Server - WebSevices
to client applications through various protocols like HTTP, TCP-IP etc. All the web.... An application server providers allows the client to access the business logic for use...Application Server and Web Server  General difference, Application
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
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
server
at the client end. He tries using the following code to create a reliable connection between server and client: public Server() { try { serverSocket... the server and clients exist on the same machine. But, when a client executes
jsp applet communication - JSP-Servlet
need to get a connection to database of the server thru applet... Thanks
Client Side and Server Side coding
Client Side and Server Side coding       The combo of client side and server side coding... to write code in both client side and server side. Some other combinations are &ndash
MySQL Client
). This general-purpose client provides a graphical interface to the MySQL server. It can... library.  * When connecting to the server with a pre-4.1 client... of client access control: * A client attempts to connect and the server either accepts
MySQL Client
connecting to the server with a pre-4.1 client program, use an account that still has... it. The server matches a client against entries in the grant tables based... applications to make SQL queries to a remote MySQL Server across a TCP/IP connection
Client Socket Information
Client Socket Information       In this section, you will learn how to get client... connectivity that is connected from server or may not. getSoTimeout
web server - WebSevices
; A web server handles the HTTP protocol while an application server exposes business logic to client applications through various protocols like HTTP, TCP-IP...web server  web server we need to restart tomcat server when we
UDP (User Datagram Protocol)
model (OSI). This protocol is similar to TCP (transmission control protocol) that is used in client/ server programs like videoconference systems expect UDP... the confirmation report. UDP and TCP both are used to transport the data
SweetDEV RIA
, Calendar, Click to open, Expand/Collapse, Excel export, client /server communication, Treeview. Read full Description
Server Sockets
the client side connection and second is server socket, which implement... that actually implement sockets. It is used to create both client and server sockets... Server Sockets     
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
What do you think about client-side/server-side coding ?
What do you think about client-side/server-side coding ?  Hi, What do you think about client-side/server-side coding
Server Sockets
the client side connection and second is server socket, which implement... that actually implement sockets. It is used to create both client and server sockets... Server Sockets     
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
run exe on remote client
run exe on remote client  I am making a client server application... file on client pc in my network if i know the username & password. I have copied files fromserver to client using my application but i cant run it on remote
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
UDP Server in Java
a reliable communication has options of using either TCP or a program based... the UDP server is stopped then you can't be sent any message by the UDP client... UDP Server in Java     
How TCP/IP works ?
How TCP/IP works ?  hello,, Can some body tell me how TCP/IP works?   hii, TCP/IP is just a protocol that allows different nodes on the network/Internet to share resources and without TRANSMISSION CONTROL PROTOCOL
Client's Data with Axis2 and Java
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... client's data? First of all back-end will be build in Java(will try to implement some
File download from server to client machine - JSP-Servlet
File download from server to client machine  hi, I want to save a pdf file to my client machine from a button provoded in a jsp page.The file... the generated report in server as follow. exporter.exportIntoPdfFile("c://reports
how to use a JInternalFrame in a JFrame to create a chat window in a client/server app?
how to use a JInternalFrame in a JFrame to create a chat window in a client/server app?  how to use a JInternalFrame within a JFrame? i want to create a client/server app. i know that JIternalFrame should be used
JayJax
.) enhanced by a Model-Presenter-Layer and the goal is to allow various communication policies between client and server. Read full Description
Database books Page8
; The programmer's Reference for client services Applications This lesson  provides of the Client Services Applications (CSAs) and defines how CSAs work. The Client Services feature of CICS allows you to write a Client

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.