Solved

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

Posted on 2007-11-25
4
1,890 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jdbc error in jsp application 20 44
Can't ping New Linux Servers 40 64
how to see all occupied ports on windows 10 laptop 15 59
Tomcat: Unable to run tomcat service. 2 18
We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

816 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

12 Experts available now in Live!

Get 1:1 Help Now