必威betway-手机版唯一官网
做最好的网站

betway必威官网手机版

当前位置:必威betway > betway必威官网手机版 > 客户端连接到服务端

客户端连接到服务端

来源:http://www.jdxzx.net 作者:必威betway 时间:2019-12-26 16:20

图片 1

服务端

publicclassXJCS{publicshortiPreviewWidth=0;publicshortiPreviewHeight=0;publicshortrefreshRate=50;//刷新率毫秒publicbyteimageQuality=60;//图像质量/***0后1前摄像头*/publicbytecameraID=0;}

publicclassSendHead{publicintcmd=0;publicintsize=0;publicintcsA=0;publicintcsB=0;

@OverridepublicvoidonPreviewFrame(byte[]data,Cameracamera){if(xjcs.refreshRate0){longl=System.currentTimeMillis();if(lexecuTime+xjcs.refreshRate){return;}execuTime=l;}YuvImg=newYuvImage(data,ImageFormat.NV21,xjcs.iPreviewWidth,xjcs.iPreviewHeight,null);byteArrOut.reset();try{YuvImg.compressToJpeg(img_rect,xjcs.imageQuality,byteArrOut);}catch(Exceptione){FF.scErr("img.compressToJpeg");e.printStackTrace();return;}comByte=byteArrOut.toByteArray();sh5.size=comByte.length;//SendHead//----------将图标添加发送列队ssoc.SQ.add(sh5,comByte,sh5.size);ssoc.SQ.exec();//--------------------------comByte=null;}

发送列队

publicclassXC_SendQueueextendsThread{Objectsync=newObject();LinkedListstruct_SendDataqueue=newLinkedListstruct_SendData();XC_SendQueue(){}privateboolean__break=false;privateboolean__Tstopped=false;privatestruct_SendDatassd;publicvoidadd(byte[]byte_,intsize){ssd=newstruct_SendData();ssd.data=byte_;ssd.size=size;queue.addFirst(ssd);}publicvoidadd(SendHeadsh,byte[]byte_,intsize){ssd=newstruct_SendData();ssd.data=toNetMsg?sh.toNetMsg():sh.toBytes();ssd.size=SendHead.HEADSIZE;queue.addFirst(ssd);ssd=newstruct_SendData();ssd.data=byte_;ssd.size=size;queue.addFirst(ssd);}publicvoidadd(struct_SendDatassd_){queue.addFirst(ssd_);}publicbooleanisAlive2(){return__Tstopped;}publicvoidinterrupt2(){__break=true;exec();}publicvoidexec(){synchronized(sync){sync.notify();}}@Overridepublicvoidrun(){struct_SendDatasj;while(true){synchronized(sync_send){while(!queue.isEmpty()){sj=queue.removeLast();try{outStream.write(sj.data,0,sj.size);}catch(IOExceptione){e.printStackTrace();FF.scErr("IOException:45124");if(!setSocketError(SocketError.ERROR_IOEXCEPTION,"XC_SendQueue:IOException:123"))return;;}}}synchronized(sync){try{sync.wait();}catch(InterruptedExceptione){e.printStackTrace();FF.scErr("sync.wait();");if(!setSocketError(SocketError.ERROR_IOEXCEPTION,"XC_SendQueue:synchronized(sync):547"))return;;}}if(__break)break;}__Tstopped=true;}}

客户端连接到服务端

booleanconnectServer(Stringip){if(csoc.socket!=null){if(csoc.isIOException==false)returntrue;}//ff.toast("开始连接...");//Socketsoc=csoc.connectToServer("192.168.43.1",1234);if(ip!=nullip.equals(""))ip=newString("192.168.43.1");if(ip==null)ip=newString("192.168.43.1");//ff.xxk(ip);Socketsoc=csoc.connectToServer(ip,1234);if(soc==null){ff.xxk("连接失败");ll_control.setVisibility(View.VISIBLE);returnfalse;}csoc.toNetMsg=false;csoc.initSocket(soc);csoc.setOnRecvSendHead(this);csoc.setOnSocketError(this);csoc.startRecv(recvBuffer);ff.setTitle("已连接");returntrue;}

@OverridepublicbooleanonSocketReceivedData(SendHeadsh,byte[]data,MySocket___sssss){switch(sh.cmd){casecommand.ML_FILE_Picture:{Gbmp=BitmapFactory.decodeByteArray(data,0,sh.size);chan.sendEmptyMessage(chan.msgImgPreviewShowBitmap);}break;returntrue;}

本文由必威betway发布于betway必威官网手机版,转载请注明出处:客户端连接到服务端

关键词: