sockets

sockets

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.

Ads









Related Tutorials/Questions & Answers:
Version of cornerstone-sockets>cornerstone-sockets-impl dependency
List of Version of cornerstone-sockets>cornerstone-sockets-impl dependency
Version of cornerstone-sockets>cornerstone-sockets-api dependency
List of Version of cornerstone-sockets>cornerstone-sockets-api dependency
Advertisements
ModuleNotFoundError: No module named 'sockets'
ModuleNotFoundError: No module named 'sockets'  Hi, My Python... 'sockets' How to remove the ModuleNotFoundError: No module named 'sockets... to install padas library. You can install sockets python with following command
Version of cornerstone-sockets-api>cornerstone-sockets-api dependency
List of Version of cornerstone-sockets-api>cornerstone-sockets-api dependency
Version of cornerstone-sockets-impl>cornerstone-sockets-impl dependency
List of Version of cornerstone-sockets-impl>cornerstone-sockets-impl dependency
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
Artifacts of cornerstone-sockets
List of Artifacts of cornerstone-sockets maven depenency
Artifacts of cornerstone-sockets-api
List of Artifacts of cornerstone-sockets-api maven depenency
Artifacts of cornerstone-sockets-impl
List of Artifacts of cornerstone-sockets-impl maven depenency
ModuleNotFoundError: No module named 'Flask-Sockets'
ModuleNotFoundError: No module named 'Flask-Sockets'  Hi, My... 'Flask-Sockets' How to remove the ModuleNotFoundError: No module named 'Flask-Sockets' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'invisibleroads-sockets'
ModuleNotFoundError: No module named 'invisibleroads-sockets'  Hi...: No module named 'invisibleroads-sockets' How to remove the ModuleNotFoundError: No module named 'invisibleroads-sockets' error? Thanks   Hi
ModuleNotFoundError: No module named 'invisibleroads-sockets'
ModuleNotFoundError: No module named 'invisibleroads-sockets'  Hi...: No module named 'invisibleroads-sockets' How to remove the ModuleNotFoundError: No module named 'invisibleroads-sockets' error? Thanks   Hi
ModuleNotFoundError: No module named 'Flask-Sockets-Tornado'
ModuleNotFoundError: No module named 'Flask-Sockets-Tornado'  Hi...: No module named 'Flask-Sockets-Tornado' How to remove the ModuleNotFoundError: No module named 'Flask-Sockets-Tornado' error? Thanks   Hi
Maven Dependency cornerstone-sockets-api >> 1.0
You should include the dependency code given in this page to add Maven Dependency of cornerstone-sockets >> cornerstone-sockets-api version1.0 in your project
Maven Dependency cornerstone-sockets-api >> 2.1
You should include the dependency code given in this page to add Maven Dependency of cornerstone-sockets-api >> cornerstone-sockets-api version2.1 in your project
Maven Dependency cornerstone-sockets-impl >> 1.0
You should include the dependency code given in this page to add Maven Dependency of cornerstone-sockets >> cornerstone-sockets-impl version1.0 in your project
Maven Dependency cornerstone-sockets-impl >> 2.1
You should include the dependency code given in this page to add Maven Dependency of cornerstone-sockets-impl >> cornerstone-sockets-impl version2.1 in your project
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
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
Parsing The XML File Using JDOM Parser in JSP
from files, network sockets, strings, or from reader. JDOM does not has its own
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
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
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
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
Java UDP
be used to send datagrams, using Datagram Sockets, to one another i.e. from client
Advance and Core JAVA Topics
Sockets Design Pattern JSP Servlets Java Beans Session Management For more

Ads