Total members 11894 |It is currently Tue Nov 26, 2024 3:07 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





echo client Socket
java code
import java.io.*;
import java.net.*;

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

Socket echoSocket = null;
DataOutputStream out = null;
DataInputStream in = null;

try {
echoSocket = new Socket("campione", 7);
out = new DataOutputStream(echoSocket.getOutputStream());
in = new DataInputStream(echoSocket.getInputStream());
} catch (UnknownHostException e) {
System.err.println("Host not known.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't connect ");
System.exit(1);
}

DataInputStream stdIn = new DataInputStream(System.in);
String userInput;

while ((userInput = stdIn.readLine()) != null) {
out.writeBytes(userInput);
out.writeByte('\n');
System.out.println("echo: " + in.readLine());
}
out.close();
in.close();
stdIn.close();
echoSocket.close();
}
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : echo client using Sockets
 apply SSL on Sockets     -  
 PHP echo command     -  
 Echo multiline string     -  
 Difference between PHP echo() and PHP print()?     -  
 echo command to output HTML     -  
 client server client     -  
 FTP Server and FTP Client     -  
 name and version of the client     -  
 CMD ie ChatServer & chat client     -  
 Java Telnet client     -  



Topic Tags

Java Networking






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com