无线上网直接的Andr​​oid无线上网、直接、oid、Andr

2023-09-06 01:18:25 作者:闭口不提从前

我想通过WifiDirect 2设备之间传输文件。

i want to transfer files between 2 devices via WifiDirect.

我想做同样的事情在WifiDirectDemo,但我不能从组的所有者将数据传送到另一台设备,所以我尝试这样做:当每一个设备的点击连接时,其他设备设置作为组所有人,每个连接上谁请求连接的设备永远是客户端,并且可以发送数据。

I wanted to do the same thing as in WifiDirectDemo but i can't transfer data from the group owner to the other device so i tried this: each time when a one of the devices clicks on connect, the other device is set as group owner so on each connection the device who asks for connection is always the client and can send data.

这里的问题是,机器人永远记住创建的第一组,因此它的组拥有者,在其他的作品我也只能在第一时间,除非我去设置和忘记第一个连接创建的组。

The problem with this is that android always remember the first group created and therefore its group owner, in other works what i did only works the first time unless i go to settings and forget the group created by the first connection.

我知道,通过断开按钮wifigroup被删除,但Android系统将其放在remembred组,并使用其设置(组所有者negociation),当一个新的连接是必须要做的。

I know that by using the disconnect button the wifigroup is removed but the android system puts it in remembred groups and uses its setting ( group owner negociation) when a new connection is to be done.

第二件事我想是创建每个设备一个ServerSocket(另一个端口),所以这样两个组所有者和其他设备将客户端和服务器在同一时间。我不知道是否该组的所有者可以设置在客户端,但我不能在这里创建两个设备上一个ServerSocket是我的code:

The second thing i tried is to create on each device a serversocket (on another port) so this way both the group owner and the other device would be clients and servers at the same time. I don't know if the group owner can be set at a client, but i cant create a serversocket on both devices here is my code:


  @Override
    public void onConnectionInfoAvailable(final WifiP2pInfo info) {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
        this.info = info;
        this.getView().setVisibility(View.VISIBLE);

        // The owner IP is now known.
        TextView view = (TextView) mContentView.findViewById(R.id.group_owner);
        view.setText( getResources().getString(R.string.group_owner_text)
                + ((info.isGroupOwner == true) ? getResources().getString(R.string.yes)
                        : getResources().getString(R.string.no)));

        // InetAddress from WifiP2pInfo struct.
        view = (TextView) mContentView.findViewById(R.id.device_info);
        view.setText("Group Owner IP - " + info.groupOwnerAddress.getHostAddress());


        // After the group negotiation, we assign the group owner as the file
        // server. The file server is single threaded, single connection server
        // socket.
        if (info.groupFormed && info.isGroupOwner) {
            new FileServerAsyncTask(getActivity(), mContentView.findViewById(R.id.status_text),8988)
                    .execute();
            mContentView.findViewById(R.id.btn_start_client).setVisibility(View.VISIBLE);
            Log.d(WiFiDirectActivity.TAG, "serveur8988cree");
        } else if (info.groupFormed) {
            // The other device acts as the client. In this case, we enable the
            // get file button.
            //in this case we create a server socket on another port
            new FileServerAsyncTask(getActivity(), mContentView.findViewById(R.id.status_text),8987)
            .execute();
            mContentView.findViewById(R.id.btn_start_client).setVisibility(View.VISIBLE);
            Log.d(WiFiDirectActivity.TAG, "serveur8987cree");
            ((TextView) mContentView.findViewById(R.id.status_text)).setText(getResources()
                    .getString(R.string.client_text));
        }

感谢您的帮助。

thanks for help.

推荐答案

要发送的数据,你需要知道receiver.For的IP地址(而不是设备地址)的p2pclient,group_owner的IP地址在Wifip2pInfo提供可变的,因此它可以使用此数据发送到GO.If组所有者知道P2P客户端的与它要发送数据的话还可以发送files.This可以通过两种方式来实现的IP地址

To send data you need to know the IP address(not the device address) of the receiver.For the p2pclient,the IP address of group_owner is available in Wifip2pInfo variable,so it can use this to send data to GO.If the group owner knows the IP address of p2p client to which it wants to send data then it can also send files.This can be achieved in two ways.

GO分配IP地址的客户端和存储有关它的信息。 在每一个新加入的客户端将其IP地址GO在加入该组织的时间。
 
精彩推荐
图片推荐