Hello,

I've just downloaded and wanted to make a simple client application that
connects to a server, and can send and receive text. I was using the NetCat
example on Apache's web site
(http://svn.apache.org/viewvc/mina/branches/1.0/example/src/main/java/org/apache/mina/example/netcat/Main.java?revision=555855&view=markup).

However for some reason it just doesn't seem to work. I use Java 1.4, so I'm
using Mina 1.0.4, Backport util 3.0 and NLog4J 1.2.25

Nothing seems to happen. The program doesn't even try to connect to the
server. I was using a TCP listener to see what's going on and the client
didn't even try to connect to the server.

The following is the source code of the entire application. Could someone
tell me what's wrong here?
Nothing is printed out on the screen.

Thanks in advance, Csaba


// Created on Aug 8, 2007

import java.io.*;
import java.net.*;
import org.apache.mina.common.*;
import org.apache.mina.transport.socket.nio.*;

public class MinaTest {

        public static void main(String[] args) throws Exception {
                
                SocketConnector connector = new SocketConnector();
                
                
((IoConnectorConfig)connector.getDefaultConfig()).setConnectTimeout(30);
                
                IoSession session = connector.connect(new
InetSocketAddress("www.google.com",80), new
MyProtocolHandler()).getSession();
                
                /*  this was supposed to send text to the server - I removed it 
after it
didn't work
                String msg = "";
                BufferedReader stdin = new BufferedReader(new
InputStreamReader(System.in));
                while (msg != null && !msg.equals("quit")) {
                        System.out.println(session);
                        msg = stdin.readLine();
                        session.write(msg);
                }
                
                session.close();
                */
        }
        
        private static class MyProtocolHandler extends IoHandlerAdapter {
                
                public void sessionOpened(IoSession session) {
                        System.out.println("Started");
                }
                
                public void sessionClosed(IoSession session) {
                        System.out.println("Finished");
                }
                
                public void sessionIdle(IoSession session, IdleStatus status) {
                        System.out.println("Connection idle");
                }
                
                public void messageReceived(IoSession session, Object message) {
                        ByteBuffer buf = (ByteBuffer) message;
                        
                // Print out read buffer content.
                        System.out.print("S = ");
                while (buf.hasRemaining()) {
                    System.out.print((char) buf.get());
                }
                
                System.out.flush();
                }
                
        }
}

-- 
View this message in context: 
http://www.nabble.com/Can%27t-make-a-simple-client-application-tf4238348s16868.html#a12059587
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.

Reply via email to