• 团队博客11


    P2P文件共享

      P2P的意思是对等网络,即对等计算机网络,处于对等网络中的计算机之间可以相互通信和共享资源如文件、外围设备等。

      根据网络中共享资源的方式的不同,局域网有两种组织形式:一种是对等网络,另一种则是工作站/服务器结构。对等网络中的计算机之间可以互相通信和共享资源;而工作站/服务器结构的网络中可将共享资源放在一台专用计算机-服务器(Server)上,工作站之间不互相直接共享资源。(来自搜狗百科)

      WifiP2PManager类的API是为了管理p2pWiFi热点的。

     @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
    
                int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
                if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
                    activity.setIsWifiP2pEnabled(true);
                } else {
                    activity.setIsWifiP2pEnabled(false);
                    activity.resetData();
    
                }
                Log.d(WiFiDirectActivity.TAG, "P2P state changed - " + state);
            } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
    
                // request available peers from the wifi p2p manager. This is an
                // asynchronous call and the calling activity is notified with a
                // callback on PeerListListener.onPeersAvailable()
                if (manager != null) {
                    manager.requestPeers(channel, (PeerListListener) activity.getFragmentManager()
                            .findFragmentById(R.id.frag_list));
                }
                Log.d(WiFiDirectActivity.TAG, "P2P peers changed");
            } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
    
                if (manager == null) {
                    return;
                }
    
                NetworkInfo networkInfo = (NetworkInfo) intent
                        .getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
    
                if (networkInfo.isConnected()) {
    
                    DeviceDetailFragment fragment = (DeviceDetailFragment) activity
                            .getFragmentManager().findFragmentById(R.id.frag_detail);
                    manager.requestConnectionInfo(channel, fragment);
                } else {
                    activity.resetData();
                }
            } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
                DeviceListFragment fragment = (DeviceListFragment) activity.getFragmentManager()
                        .findFragmentById(R.id.frag_list);
                fragment.updateThisDevice((WifiP2pDevice) intent.getParcelableExtra(
                        WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));
            }
        }
    

      

  • 相关阅读:
    linux网卡eth1如何修改为eth0
    rpm方式安装MySQL5.1.73
    quartz demo01
    chrome 搜索 jsonView
    判断是否十六进制格式字符串
    ip and port check 正则
    hadoop 遇到java.net.ConnectException: to 0.0.0.0:10020 failed on connection
    hadoop2.4.1 伪分布
    R 包
    使用pt-heartbeat检测主从复制延迟
  • 原文地址:https://www.cnblogs.com/XJXYJ/p/5863160.html
Copyright © 2020-2023  润新知