Solved

server /client Java code (simple form...)

Posted on 2007-11-25
4
1,885 Views
Last Modified: 2013-11-23
I want to fill properly the following code to connect with a server and to bet back (echo) anything I type...
import java.net.*;

import java.io.*;

import java.util.*;

class ServerTest{

	public static void main(String[] args)throws UnknownHostException,IOException{

	

	Scanner input=new Scanner(System.in);	

	Socket client;

	String serverName="pop.mail.yahoo.com";

	try{

	//trying to establish a connection to serverName

	client=new Socket(serverName,110);

	System.out.println("connected with "+serverName);

	System.out.print("enter a string to be echoed: ");

	String string=input.nextLine();

	//what I have to write here??????

	}

	catch(UnknownHostException e){

		System.out.println("exception: "+e);

	}

	catch (IOException e){

		System.out.println("exception : "+e);

	}	

	}

}

Open in new window

0
Comment
Question by:dimi67
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 20347153
0
 

Author Comment

by:dimi67
ID: 20348866
well, this is not what I 'm asking...
0
 
LVL 17

Accepted Solution

by:
contactkarthi earned 500 total points
ID: 20365888
have a look at the question in the following post

http://www.experts-exchange.com/Programming/Languages/Java/Q_22959757.html

the asker has a program that send info to server and he gets responses back from server

below are some lines from there that you are looking

 String remoteServer = "localhost";
         
        try {
            // Try connecting to the 'remote' machine on port 4445
            serverSocket = new Socket(remoteServer, 4445);
            toServer = new PrintWriter(serverSocket.getOutputStream(), true);
            fromServer = new BufferedReader(new InputStreamReader(
                                        serverSocket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host: " + remoteServer);
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for "
                               + "the connection to: " + remoteServer);
            System.exit(1);
        } // try-catch


toServer.println(balance); // send message to server
reply = fromServer.readLine();// get response from server
0
 
LVL 17

Expert Comment

by:contactkarthi
ID: 20365946
or look in

http://www.exampledepot.com/egs/java.net/CreateServerSocket.html

and its related links at the bottom of the above page
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Understanding FTPS File transfer is a common requirement in most Enterprises. While there are numerous ways to get a file from Point A to Point B over a network, perhaps the most common method still in use is FTP – File Transfer Protocol. FTP is …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now