简体   繁体   English

使用套接字发送TCP / IP命令

[英]Sending TCP/IP command using socket

I am completely new to Java and slowly learning the basics so apologies if this sounds idiotic. 我是Java的新手,如果听上去很愚蠢,就慢慢地学习一些基础知识。

I am trying to create an application that on a button click it sends a specific command to a certain IP and Port. 我正在尝试创建一个应用程序,单击该按钮后,它将向特定IP和端口发送特定命令。 The port will be fixed at Port 32, but the IP will be taken from an Intent. 该端口将固定在端口32,但IP将从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. 它需要连接到IP,发送“ Root”(用户名)命令,然后等待答复,然后发送另一个命令“ Root”(密码),然后等待另一个答复,然后在建立连接后,我希望能够在单击按钮时发送更多命令。

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. 我将正确地学习Java,这是我要做的事情,但这对于我首先完成至关重要。

If someone could help it would be extremely appreciated. 如果有人可以帮助,将不胜感激。

Here is full example of TCP/IP type of work in android 这是android中TCP / IP类型工作的完整示例

TCP /IP TCP / IP

Java has very little to do with this. Java与此无关。

On the client side, you have to use the network tools provided by the Android platform. 在客户端,您必须使用Android平台提供的网络工具。 For example, if want to use the HTTP (web) protocol, see: http://developer.android.com/reference/android/net/http/package-summary.html . 例如,如果要使用HTTP(网络)协议,请参见: 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. 在服务器端,您需要有一个HTTP服务器来接受您的调用并处理它们。 You can easily build something like this with Sinatra: http://www.sinatrarb.com/ . 您可以使用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). 如果您不喜欢像Sinatra这样的基于Ruby的框架,则可以轻松地找到许多其他基于Java的框架(但是Java对于此任务而言要复杂得多)。

BTW: The tool you trying to build is usually known as "authentication system" or "login system". 顺便说一句:您尝试构建的工具通常称为“身份验证系统”或“登录系统”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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