• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

sending data to telnet server

Hi i'm just starting android studio for the most part. i'm following this tutorial on setting up sockets trying to get familiar with things. i can compile and run the application in the tutorial but the server i'm trying to send data to is a telnet server. the server just sits and waits for specific strings to do specific things. how can i modify this code to send strings to the telnet server? or is that exactly what this is doing and maybe i need to encode it into bytes?

Java:
package com.javacodegeeks.android.androidsocketclient;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Client extends Activity {

private Socket socket;

private static final int SERVERPORT = 23;
private static final String SERVER_IP = "10.0.0.50";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    new Thread(new ClientThread()).start();
}

public void onClick(View view) {
    try {
        EditText et = (EditText) findViewById(R.id.EditText01);
        String str = et.getText().toString();
        PrintWriter out = new PrintWriter(new BufferedWriter(
                new OutputStreamWriter(socket.getOutputStream())),
                true);
        out.println(str);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

class ClientThread implements Runnable {

    @Override
    public void run() {

        try {
            InetAddress serverAddr = InetAddress.getByName(SERVER_IP);

            socket = new Socket(serverAddr, SERVERPORT);

        } catch (UnknownHostException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

    }

}
 
Back
Top Bottom