简体   繁体   中英

Sending TCP/IP command using socket

I am completely new to Java and slowly learning the basics so apologies if this sounds idiotic.

I am trying to create an application that on a button click it sends a specific command to a certain IP and Port. The port will be fixed at Port 32, but the IP will be taken from an Intent.

public class IPControl extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get the message from the intent
    Intent intent = getIntent();
    String message = intent.getStringExtra(IPEntry.ACTUALIP);

This is as far have gotten.

It will need to connect to the IP send a command of "Root" (Username) and then wait for a reply then send another command 'Root' (Password) and then wait for another reply, then after the connection has been established, I want to be able to send further commands on button click.

I have been racking my brains and searching the web for days and cannot seem to find the right solution.

I am going to be learning Java properly, it is on my list of things to do but this is vital for me to complete first.

If someone could help it would be extremely appreciated.

Here is full example of TCP/IP type of work in android

TCP /IP

Java has very little to do with this.

On the client side, you have to use the network tools provided by the Android platform. For example, if want to use the HTTP (web) protocol, see: http://developer.android.com/reference/android/net/http/package-summary.html .

On the server side, you need to have a HTTP server that accepts your calls and handles them. You can easily build something like this with Sinatra: http://www.sinatrarb.com/ . If you do not like a Ruby based framework, like Sinatra, you can easily find many others based on Java (but Java is much more complicated for this task).

BTW: The tool you trying to build is usually known as "authentication system" or "login system".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM