手机客户端与电脑服务器端通过Socket传递序列化对象是遇到异常 手机作为客户端,电脑作为服务器进行android socke...
\u5173\u4e8epython socket\u7684\u5c0f\u95ee\u9898\uff01\u600e\u4e48\u5728\u670d\u52a1\u5668\u7aef\u548c\u5ba2\u6237\u7aef\u4e4b\u95f4\u4f20\u8f93\u5bf9\u8c61\uff01\u901a\u5e38\u505a\u6cd5\u662f\u3002\u6253\u5305\u6570\u636e\u5305\u3002 \u4e00\u822c\u662fxml \u6216json \u6bd4\u8f83\u7b80\u5355\u901a\u7528\u3002\u5927\u591a\u7f16\u7a0b\u652f\u6301\u7684\u7f16\u7801\u5e93\u5c31\u597d\u3002java\u6709json. python\u4f30\u8ba1\u4e5f\u6709json\u5e93\u3002\u81ea\u5df1\u641c\u4e0b\u3002
1.PC\u670d\u52a1\u5668\u542f\u7528ServerSocket\u4e24\u4e2a\u901a\u4fe1\u5b9e\u4f53\u5728\u5efa\u7acb\u865a\u62df\u94fe\u8def\u4e4b\u524d\uff0c\u9700\u8981\u6709\u4e00\u65b9\u5148\u51c6\u5907\u597d\uff0c\u4e3b\u52a8\u63a5\u53d7\u6765\u81ea\u5176\u4ed6\u901a\u4fe1\u5b9e\u4f53\u7684\u8fde\u63a5\u8bf7\u6c42\u3002\u4f7f\u7528ServerSocket\u5bf9\u8c61\u76d1\u542c\u6765\u81ea\u5ba2\u6237\u7aef\u7684Socket\u8fde\u63a5\u3002//\u521b\u5efaServerSocket\u5bf9\u8c61ServerSocketss=newServerSocket(30000);//\u76d1\u542c\u6765\u81ea\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42while(true){Sockets=ss.accept();\u2026}\u5982\u679c\u6ca1\u6709\u8fde\u63a5\uff0c\u5219\u5c06\u4e00\u76f4\u5904\u4e8e\u7b49\u5f85\u72b6\u6001\u3002\u5f53\u63a5\u6536\u5230\u8fde\u63a5\u8bf7\u6c42\u540e\uff0c\u83b7\u53d6\u6d88\u606f\u5230\u8f93\u5165\u6d41\uff0c\u5e76\u4fdd\u5b58\u5230\u6587\u4ef6\u3002//\u63a5\u6536\u5ba2\u6237\u7aef\u6d88\u606fBufferedReaderin=newBufferedReader(newInputStreamReader(client.getInputStream()));Stringstr;BufferedWriterbw=newBufferedWriter(newFileWriter("D:/ApInfo"+(i++)+".txt"));while((str=in.readLine())!=null){System.out.println(str);bw.write(str);bw.newLine();}2.Android\u7ec8\u7aef\u4f7f\u7528Socket\u901a\u4fe1\u5ba2\u6237\u7aef\u4f7f\u7528Socket\u7684\u6784\u9020\u5668\u8fde\u63a5\u670d\u52a1\u5668\uff0c\u6307\u5b9a\u670d\u52a1\u5668IP\u548c\u7aef\u53e3\u53f7\u5c31\u53ef\u4ee5\u4e86\u3002Sockets=newSocket(\u201c192.168.1.100\u201d,30000);\u8fd9\u6837\u670d\u52a1\u5668\u7aef\u7684accept()\u65b9\u6cd5\u5c31\u5f97\u5230\u54cd\u5e94\uff0c\u4ece\u800c\u5411\u4e0b\u6267\u884c\uff0c\u670d\u52a1\u5668\u7aef\u548c\u5ba2\u6237\u7aef\u5c31\u5f62\u6210\u4e86\u4e00\u5bf9\u4e92\u76f8\u8fde\u63a5\u7684Socket\u3002\u518d\u8fdb\u884c\u901a\u4fe1\u65f6\u5c31\u6ca1\u6709\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4e4b\u5206\u4e86\uff0c\u90fd\u662f\u901a\u8fc7\u8f93\u5165\u8f93\u51fa\u6d41\u8fdb\u884c\u901a\u4fe1\u3002\u8be6\u7ec6\u6b65\u9aa4\uff1a\u91c7\u7528Handler\u548cTimerTask\u6765\u5b9a\u65f6\u626b\u63cfAP\u4fe1\u606f\u5e76\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7aef\u3002TimerTask\u89c4\u5b9a\u4e86\u5230\u8fbe\u6307\u5b9a\u7684\u65f6\u95f4\u6240\u8981\u8fdb\u884c\u7684\u4efb\u52a1\u3002TimerTasktask=newTimerTask(){publicvoidrun(){Messagemessage=newMessage();message.what=1;handler.sendMessage(message);}};handler\u4f20\u9012message\u5185\u5bb9\uff1aHandlerhandler=newHandler(){publicvoidhandleMessage(Messagemsg){switch(msg.what){case1://\u6267\u884c\u5b9a\u65f6\u5668\u65f6\u95f4\u5230\u4e86\u4e4b\u540e\u7531handler\u4f20\u9012\u7684\u4efb\u52a1break;}super.handleMessage(msg);}}\u63a5\u4e0b\u6765\u626b\u63cfAP\u4fe1\u606f\u5e76\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7aef\uff0c\u7136\u540e\u5c06\u7ed3\u679c\u4fdd\u5b58\u3002WifiManagerwifiManager=(WifiManager)getSystemService(WIFI_SERVICE);wifiManager.startScan();mWifiList=wifiManager.getScanResults();\u7531WifiManager\u8bf4\u660e\u53ef\u77e5\uff0c\u5b83\u53ef\u4ee5\u7528\u4e8e\u5904\u7406\u5df2\u914d\u7f6e\u7684\u7f51\u7edc\uff0c\u5f53\u524d\u8fde\u63a5\u7684\u7f51\u7edc\u53caAP\u4fe1\u606f\u7684\u626b\u63cf\u7b49\u60c5\u51b5\u3002\u5411\u670d\u52a1\u5668\u53d1\u9001\u6d88\u606f\uff1asocket=newSocket("192.168.1.211",30000);//\u5411\u670d\u52a1\u5668\u7aef\u53d1\u9001\u6d88\u606fPrintWriterout=newPrintWriter(newBufferedWriter(newOutputStreamWriter(socket.getOutputStream())),true);out.println(message);\u5176\u4e2dmessage\u4e3a\u83b7\u53d6\u7684AP\u4fe1\u606f\uff0c\u6d4b\u8bd5\u6536\u5230\u7684\u4fe1\u606f\u683c\u5f0f\u4e3a\uff1aSSID:ICIS_LAB,BSSID:1c:af:f7:9a:65:e4,capabilities:[WPA-PSK-TKIP+CCMP],level:-80,frequency:2437
eof异常八成是流没关闭的意思,注意检查这方面,如果实在出现这个异常,可以试试再把数据发送一次,一般第一次失败 第二次就成功绛旓細B/S缁撴瀯(Browser/Server缁撴瀯)缁撴瀯鍗虫祻瑙堝櫒鍜屾湇鍔″櫒缁撴瀯銆傚畠鏄殢鐫Internet鎶鏈殑鍏磋捣,瀵笴/S缁撴瀯鐨勪竴绉嶅彉鍖栨垨鑰呮敼杩涚殑缁撴瀯銆傚湪杩欑缁撴瀯涓,鐢ㄦ埛宸ヤ綔鐣岄潰鏄氳繃WWW娴忚鍣ㄦ潵瀹炵幇,鏋佸皯閮ㄥ垎浜嬪姟閫昏緫鍦ㄥ墠绔(Browser)瀹炵幇,浣嗘槸涓昏浜嬪姟閫昏緫鍦鏈嶅姟鍣ㄧ(Server)瀹炵幇,褰㈡垚鎵璋撲笁灞3-tier缁撴瀯銆傝繖鏍峰氨澶уぇ绠鍖栦簡瀹㈡埛绔數鑴杞借嵎,鍑...
绛旓細瀹冧滑鐨勪富瑕佸尯鍒湪浜庡浣曞鐞嗙敤鎴风殑璇锋眰鍜屾暟鎹殑澶勭悊鏂瑰紡銆侰/S锛圕lient/Server锛屽鎴风/鏈嶅姟鍣ㄧ锛夋灦鏋勭殑鐗圭偣鏄互瀹㈡埛绔蒋浠舵垨绋嬪簭浣滀负鐢ㄦ埛鐣岄潰鍜屾暟鎹鐞嗙殑涓讳綋銆傜敤鎴閫氳繃瀹㈡埛绔绋嬪簭涓庢湇鍔″櫒杩涜浜や簰锛屼紶杈撳拰鎺ユ敹鏁版嵁銆傛墍鏈夌殑璁$畻鍜屾暟鎹鐞嗕富瑕佸湪瀹㈡埛绔畬鎴愶紝鏈嶅姟鍣ㄥ彧璐熻矗鎻愪緵鏁版嵁鍜屽搷搴斿鎴风鐨勮姹傘傝繖绉...
绛旓細C/S鏋舵瀯锛屽叏绉颁负Client/Server缁撴瀯锛屽嵆瀹㈡埛绔笌鏈嶅姟鍣ㄧ鐨勪氦浜掓ā寮忋傝繖绉嶆灦鏋勬槸杞欢绯荤粺璁捐鐨勬牳蹇冿紝瀹冮氳繃灏嗕换鍔″垎瑙d负瀹㈡埛绔拰鏈嶅姟鍣ㄧ鐨勯儴鍒嗭紝瀹炵幇浜嗛珮鏁堝埄鐢ㄤ袱绔‖浠惰祫婧愶紝闄嶄綆浜嗛氫俊寮閿銆傚湪杩囧幓锛屽ぇ閮ㄥ垎搴旂敤杞欢閮介噰鐢ㄨ繖绉嶄袱灞傜粨鏋勶紝闅忕潃鎶鏈彂灞曪紝Web搴旂敤閫愭笎宕涜捣锛屼笌C/S搴旂敤鍚屾牱鍏峰澶勭悊涓氬姟鐨勮兘鍔涳紝...
绛旓細B/S(Browser/Server)缁撴瀯鍗虫祻瑙堝櫒鍜屾湇鍔″櫒缁撴瀯銆傚畠鏄殢鐫Internet鎶鏈殑鍏磋捣,瀵笴/S缁撴瀯鐨勪竴绉嶅彉鍖栨垨鑰呮敼杩涚殑缁撴瀯銆傚湪杩欑缁撴瀯涓,鐢ㄦ埛宸ヤ綔鐣岄潰鏄氳繃WWW娴忚鍣ㄦ潵瀹炵幇,鏋佸皯閮ㄥ垎浜嬪姟閫昏緫鍦ㄥ墠绔(Browser)瀹炵幇,浣嗘槸涓昏浜嬪姟閫昏緫鍦鏈嶅姟鍣ㄧ(Server)瀹炵幇,褰㈡垚鎵璋撲笁灞3-tier缁撴瀯銆傝繖鏍峰氨澶уぇ绠鍖栦簡瀹㈡埛绔數鑴杞借嵎,鍑忚交浜嗙郴缁...
绛旓細C/S鏋舵瀯灏辨槸瀹㈡埛/鏈嶅姟鍣ㄦā寮,瀹㈡埛绔悜鏈嶅姟鍣ㄧ鍙戦佽姹傦紝鏈嶅姟鍣ㄧ浼氬悜瀹㈡埛绔繑鍥炴秷鎭鏈嶅姟鍣ㄧ涓庡鎴风鏈川娌℃湁鍖哄埆閮芥槸璁$畻鏈銆傜畝鍗曡锛屽彂閫佽姹傜殑涓绔氨鍙鎴风锛屾帴鍙楄姹傚苟鐩稿簲璇锋眰鐨勫氨鍙湇鍔″櫒绔
绛旓細鎯冲綋骞翠负浜嗗疄鐜癤ML浜や簰鏁版嵁锛屽嚑涔庢妸缃戠粶缈讳簡涓亶銆傚挌锛屼竴鍧楃爾澶翠笂鏉ヤ簡銆傚懙鍛碉紝搴熻瘽灏戣锛屼笅闈㈡垜浠氨杩涘叆姝i銆侭/S妯″紡鍒嗕负鏈嶅姟鍣ㄧ鍜屽鎴风锛屽鎴风鎺ュ彈鐢ㄦ埛鐨勮姹傦紝瀹㈡埛绔悜搴旂敤鏈嶅姟鎻愬嚭璇锋眰锛屽簲鐢ㄦ湇鍔′粠鏁版嵁搴撴湇鍔′腑鑾峰緱鏁版嵁锛屽簲鐢ㄦ湇鍔″皢鏁版嵁杩涜璁$畻骞跺皢缁撴灉鎻愪氦缁欏鎴风锛屽鎴风灏嗙粨鏋滃憟鐜扮粰鐢ㄦ埛銆傝繖鏍...
绛旓細1銆佸畾涔変笉鍚岋細瀹㈡埛绔锛氬鎴风锛圕lient锛夋垨绉颁负鐢ㄦ埛绔锛屾槸鎸囦笌鏈嶅姟鍣ㄧ浉瀵瑰簲锛屼负瀹㈡埛鎻愪緵鏈湴鏈嶅姟鐨勭▼搴忋鏈嶅姟鍣ㄧ锛氭湇鍔″櫒绔紝浠庡箍涔変笂璁诧紝鏈嶅姟鍣ㄦ槸鎸囩綉缁滀腑鑳藉鍏跺畠鏈哄櫒鎻愪緵鏌愪簺鏈嶅姟鐨璁$畻鏈绯荤粺锛堝鏋滀竴涓PC瀵规湇鍔″櫒绔鎻愪緵ftp鏈嶅姟锛屼篃鍙互鍙湇鍔″櫒锛夈2銆佺▼搴忕紪鍐欙細瀹㈡埛绔細瀹㈡埛绔▼搴忎笉闇瑕佹垜浠...
绛旓細涓嶅叏灞炰簬C/S鏋舵瀯锛鎵嬫満APP杞欢闄や簡C/S鏋舵瀯锛岃繕鏈夊崟鏈虹増APP锛孊/S鏋舵瀯绛夌被鍨嬬殑APP銆傚湪C/S缁撴瀯涓紝搴旂敤绋嬪簭鍒嗕负涓ら儴鍒:鏈嶅姟鍣ㄩ儴鍒鍜屽鎴锋満閮ㄥ垎銆傛湇鍔″櫒閮ㄥ垎鏄涓敤鎴峰叡浜殑淇℃伅涓庡姛鑳斤紝鎵ц鍚庡彴鏈嶅姟銆傚吀鍨嬬殑濡備竴浜涜亰澶〢PP锛岃棰慉PP绛夊氨鏄綔涓烘湰鍦板鎴锋満锛涓庢湇鍔″櫒绔杩涜淇℃伅浜ゆ祦銆佽姹傜瓑锛屽睘浜庡吀鍨嬬殑C/...
绛旓細鏈嶅姟鍣ㄧ锛氭湇鍔″櫒绔紝浠庡箍涔変笂璁诧紝鏈嶅姟鍣ㄦ槸鍚戠綉缁滀笂鐨勫叾浠栨満鍣ㄦ彁渚涙煇浜涙湇鍔$殑璁$畻鏈绯荤粺锛堝鏋滀竴涓PC瀵规湇鍔″櫒绔鎻愪緵ftp鏈嶅姟锛屼篃鍙互鍙湇鍔″櫒锛夈2銆佸偍瀛樻柟寮忎笉鍚岋細瀹㈡埛绔锛氬鎴风涓嶅崰鐢ㄥ偍瀛樼┖闂淬傛湇鍔″櫒绔細鍖呮嫭SAS/SATA銆丳CIe闂瓨鍗°丯VMe闂瓨鍜屽弻鍒楃洿鎻掑紡鍐呭瓨鎻掓Ы鐨勫疄鐜板湪鍐呮湁澶氱鏂瑰紡閮ㄧ讲鏈嶅姟鍣ㄧ...
绛旓細C/S缁撴瀯锛屽嵆Client/Server (瀹㈡埛鏈/鏈嶅姟鍣) 缁撴瀯锛屾槸澶у鐔熺煡鐨勮蒋浠剁郴缁熶綋绯荤粨鏋勶紝閫氳繃灏嗕换鍔″悎鐞嗗垎閰嶅埌Client绔拰Server绔紝闄嶄綆浜嗙郴缁熺殑閫氳寮閿锛岄渶瑕佸畨瑁瀹㈡埛绔鎵嶅彲杩涜绠$悊鎿嶄綔銆侭/S缁撴瀯锛屽嵆Browser/Server (娴忚鍣/鏈嶅姟鍣) 缁撴瀯锛屾槸闅忕潃Internet鎶鏈殑鍏磋捣锛屽C/S缁撴瀯鐨勪竴绉嶅彉鍖栨垨鑰呮敼杩涚殑缁撴瀯銆