Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-11-25
4
Medium Priority
?
1,894 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 2000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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…
Suggested Courses

604 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