Results 1 to 2 of 2
  1. #1
    Lord Josh 1 is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default New to Java Sockets

    Hey everyone,

    I'm want to setup a simple reader that outputs the information on a server when requested. For example, when I telnet to this server it automatically print's out, "Hello world!". Although when I made a simple Java socket connector, it doesn't print anything. What I want to achieve, in the long term, is being able to read and write to this server.

    Here is the code that I'm using:

    Java Code:
    public void connect() throws IOException{
    		String host = "172.16.0.118";
    		int port = 6112;
    		
    		Socket socket = new Socket(host, port);
    		BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream( )));
    		BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream( )));
    		while(true){
    			System.out.println(reader);
    		}
    	}
    How would I get it to output whatever comes from the server, then write something else to the server? :)

  2. #2
    glauber is offline Member
    Join Date
    Feb 2011
    Location
    São José dos Campos, Brazil
    Posts
    6
    Rep Power
    0

    Default

    I've also started to deal with sockets in the past week. There's plenty of tutorials/examples online. Try this one.

Similar Threads

  1. voice chat in java with sockets
    By krati in forum Networking
    Replies: 0
    Last Post: 05-12-2010, 10:17 AM
  2. Java Sockets
    By PhQ in forum New To Java
    Replies: 2
    Last Post: 05-07-2010, 12:34 PM
  3. Request-Reply With Java Sockets
    By grassbl8d in forum Networking
    Replies: 0
    Last Post: 03-03-2010, 07:11 PM
  4. Java sockets
    By Camzie in forum NetBeans
    Replies: 3
    Last Post: 12-22-2009, 05:39 PM
  5. Java application using sockets!
    By rameshraj in forum Threads and Synchronization
    Replies: 1
    Last Post: 06-11-2008, 07:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •