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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


venkatesh
sockets
1 Answer(s)      6 years and 2 months ago
Posted in : JNDI



Advertisement
View Answers

July 30, 2008 at 4:45 PM


Hi friend,

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

public class KnockKnockClient {
public static void main(String[] args) throws IOException {

Socket soc = null;
PrintWriter out = null;
BufferedReader in = null;

try {
soc = new Socket("vinod", 135);
out = new PrintWriter(soc.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host: vinod.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to: vinod.");
System.exit(1);
}

BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String fromServer;
String fromUser;

while ((fromServer = in.readLine()) != null) {
System.out.println("Server: " + fromServer);
if (fromServer.equals("Bye."))
break;

fromUser = stdIn.readLine();
if (fromUser != null) {
System.out.println("Client: " + fromUser);
out.println(fromUser);
}
}

out.close();
in.close();
stdIn.close();
soc.close();
}
}


----------------------------------------------------------------

Read for more information.

http://www.roseindia.net/java/network/interfaces-list.shtml

Thanks.


Related Tutorials/Questions & Answers:
Server Sockets
Server Sockets       In common language we can say that the sockets are just like... Sockets. The main work of ServerSocket class is to wait for a request of connection
Server Sockets
Server Sockets       In common language we can say that the sockets are just like... Sockets. The main work of ServerSocket class is to wait for a request of connection
Advertisements
how to connect client to server using Sockets
how to connect client to server using Sockets  how to connect client to server using Sockets
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using sockets?like we get a first message with 2 buttonsand on clicking one button we
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using sockets?like we get a first message with 2 buttonsand on clicking one button we
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using sockets?like we get a first message with 2 buttonsand on clicking one button we
Current Running Projects on roseindia.net
communication using TCP/IP Sockets using C++ - Call Flow 1 For complete list of Projects
SSL Certificates
SSL Certificates Secure Sockets Layer or SSL for short is a protocol. It was developed by Netscape for transmitting private documents over internet. SSL uses a cryptographic system which uses two keys to encrypt and decrypt the data
Parsing The XML File Using JDOM Parser in JSP
from files, network sockets, strings, or from reader. JDOM does not has its own
VoIP Routers
sockets, to provide Voice-Over-IP (VoIP) facilities - just like having two extra
socket - Java Beginners
socket  in a chat application i have used two sockets s1 and s2... client program. i have created only one server socket for all the sockets... use multiple server sockets in a application? suppose if i will use multiple
Structural Design Patterns
there are several sockets of different sizes, and shapes in a house. Due to variation in sizes, all the sockets are not capable of plugin a mobile charger. So we use an Adapter to make it portable across different sockets. Here Adapter works
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
Ruby/EventMachine
Ruby/EventMachine       Ruby/EventMachine is a fast, simple event-processing library for Ruby programs. It lets you write network clients and servers without handling sockets- all you do
Java Socket
Java Socket  What is a socket?  Sockets are communication... the network. It is important to note that these sockets are software, not hardware, like a wall socket.  Sockets are communication channels, which facilitate
RMI in internet - RMI
RMI in internet  dear friends. i want to develop an application for controlling a PC from a remote location in Java. communication is done through internet. so is it possible to use RMI, or Sockets for internet communication
java basics
or open sockets before getting garbage collected
Core Java Training Topics
Abstract Window Toolkit (AWT) Threads  Sockets Networking... Identifying Your Computer's IP Address Using the InetAddress Class Sockets... of a Socket Using the Remote File Copy Application Datagram Sockets
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
What is WTLS?
), formerly known as Secure Sockets Layer (SSL
thread inside other thread - Java Server Faces Questions
is in closing the sockets I donot know exactly where can I close the second socket
thread inside other thread - Java Beginners
the sockets I donot know exactly where can I close the second socket
Overview of Networking through JAVA
a brief summary of networking in a very simple manner that how to use URLs, sockets... computer which is known as ?server?. 3. Sockets and Ports  In this section we are going to explain the work of sockets in more generic way
Overview of Networking through JAVA
a brief summary of networking in a very simple manner that how to use URLs, sockets... computer which is known as ?server?. 3. Sockets and Ports  In this section we are going to explain the work of sockets in more generic way
Advance and Core JAVA Topics
Sockets Design Pattern JSP Servlets Java Beans Session Management For more
Java UDP
be used to send datagrams, using Datagram Sockets, to one another i.e. from client
Adapter Pattern
take an example: Suppose there are several sockets of different sizes, and shapes in a house. Due to variation in sizes, all the sockets are not capable... different sockets. Here Adapter works as a connector. This connector connects them
Package categories in Java
It provides classes for network support, including URLs, TCP sockets, UDP sockets,  IP addresses, and a binary-to-text
UDP - User Datagram Protocol
at a time.    Experiment with UDP sockets   ... sockets  
 

 

 

DMCA.com