Solved

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

Posted on 2007-11-25
4
1,892 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article explains the protocols and technology which is involved when two computers on different TCP/IP networks communicate with each other. In the diagram, a router is used to segregate two networks. The networks are 192.168.1.0/24 and 192…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…

729 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