新闻中心

大发888网上投注凭你现在的实力

2016-03-10 来源: 作者:陈延鹏 责任编辑:田艳敏

摘 要:大发888网上投注凭你现在的实力 y7ic82

 大发888网上投注凭你现在的实力

工程目录: 下面上代码:客户端代码:[csharp] view plaincopyprint?usingUnityEngine;usingSystem;usingSystem.Collections;usingLSocket.Net;usingLSocket.Type;usingLSocket.cmd;publicclassSocketDemo:MonoBehaviour{publicUnitySocket[]socket;publicString[]textAreaString;publicString[]textFieldString;publicGUISkinmySkin;//Usethisforinitialization voidStart(){socket=newUnitySocket[4];textAreaString=newString[12];for(inti=0;i<12;i++){textAreaString[i]="";}textFieldString=newString[4];for(inti=0;i<4;i++){textFieldString[i]="";}}//UpdateiscalledonceperframevoidUpdate(){}voidOnGUI(){GUI.skin=mySkin;for(inti=0;i<4;i++){Strings=textAreaString[i*3]+"\n"+textAreaString[i*3+1]+"\n"+textAreaString[i*3+2];GUI.TextArea(newRect(i%2*Screen.width/2,i/2*(Screen.height/2)+50,100,60),s);textFieldString[i]=GUI.TextField(newRect(i%2*Screen.width/2+50,i/2*(Screen.height/2),100,20),textFieldString[i]);if(GUI.Button(newRect(i%2*Screen.width/2,i/2*(Screen.height/2),40,20),"连接")){socket[i]=null;socket[i]=newUnitySocket();socket[i].SocketConnection("192.168.0.8",10000,this,i);socket[i].DoLogin(textFieldString[i]);}elseif(GUI.Button(newRect(i%2*Screen.width/2,i/2*(Screen.height/2)+25,40,20),"关闭")){if(socket[i]!=null){socket[i].close();socket[i]=null;}}}if(GUI.Button(newRect(Screen.width-60,Screen.height-30,60,30),"退出")){Application.Quit();}}} using UnityEngine; using System; using System.Collections; using LSocket.Net; using LSocket.Type; using LSocket.cmd; public class SocketDemo : MonoBehaviour { public UnitySocket[] socket; public String[] textAreaString; public String[] textFieldString; public GUISkin mySkin; // Use this for initialization void Start() { socket = new UnitySocket[4]; textAreaString = new String[12]; for (int i = 0; i < 12; i++) { textAreaString[i] = ""; } textFieldString = new String[4]; for(int i=0;i<4;i++){ textFieldString[i] = ""; } } // Update is called once per frame void Update() { } void OnGUI() { GUI.skin = mySkin; for (int i = 0; i < 4; i++) { String s = textAreaString[i * 3] + "\n" + textAreaString[i * 3 + 1] + "\n" + textAreaString[i * 3 + 2]; GUI.TextArea(new Rect(i % 2 * Screen.width / 2, i / 2 * (Screen.height / 2) + 50, 100, 60), s); textFieldString[i] = GUI.TextField(new Rect(i % 2 * Screen.width / 2+50, i / 2 * (Screen.height / 2), 100, 20), textFieldString[i]); if (GUI.Button(new Rect(i % 2 * Screen.width / 2, i / 2 * (Screen.height / 2), 40, 20), "连接")) { socket[i] = null; socket[i] = new UnitySocket(); socket[i].SocketConnection("192.168.0.8", 10000, this, i); socket[i].DoLogin(textFieldString[i]); } else if (GUI.Button(new Rect(i % 2 * Screen.width / 2, i / 2 *( Screen.height / 2) + 25, 40, 20), "关闭")) { if (socket[i] != null) { socket[i].close(); socket[i] = null; } } } if (GUI.Button(new Rect(Screen.width - 60, Screen.height - 30, 60, 30), "退出")) { Application.Quit(); } } }[csharp] view plaincopyprint?namespaceLSocket.Net{/****@authorfeng侠,qq:313785443*@date2010-12-23**///描述:封装c#socket大发888网上投注凭你现在的实力 传输协议usingUnityEngine;usingSystem;usingSystem.Net.Sockets;usingSystem.Net;usingSystem.Collections;usingSystem.Text;usingSystem.Threading;usingLSocket.Type;usingLSocket.cmd;classSocketThread{UnitySocketsocket;SocketDemodemo;intidx;publicSocketThread(UnitySocketsocket,SocketDemodemo,intidx){this.socket=socket;this.demo=demo;this.idx=idx;}publicvoidrun(){while(true){try{Strings=socket.ReceiveString();demo.textAreaString[idx*3]=demo.textAreaString[idx*3+1];demo.textAreaString[idx*3+1]=demo.textAreaString[idx*3+2];demo.textAreaString[idx*3+2]=s;MonoBehaviour.print(s+""+idx);}catch(Exceptione){MonoBehaviour.print(e.ToString());socket.t.Abort();}}}}publicclassUnitySocket{publicSocketmSocket=null;publicThreadt=null;privateSocketThreadst=null;publicSocketDemodemo=null;publicUnitySocket(){}publicvoidSocketConnection(stringLocalIP,intLocalPort,SocketDemodemo,intidx){this.demo=demo;mSocket=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);try{IPAddressip=IPAddress.Parse(LocalIP);IPEndPointipe=newIPEndPoint(ip,LocalPort);mSocket.Connect(ipe);st=newSocketThread(this,demo,idx);t=newThread(newThreadStart(st.run));t.Start();}catch(Exceptione){MonoBehaviour.print(e.ToString());}}publicvoidclose(){mSocket.Close(0);mSocket=null;}publicvoidDoLogin(StringuserName){try{Send(CommandID.LOGIN);Send(userName);}catch(Exceptione){MonoBehaviour.print(e.ToString());}}publicvoidSend(floatdata){byte[]longth=TypeConvert.getBytes(data,true);mSocket.Send(longth);}publicfloatReceiveFloat(){byte[]recvBytes=newbyte[4];mSocket.Receive(recvBytes,4,0);//从服务器端接受返回信息floatdata=TypeConvert.getFloat(recvBytes,true);returndata;}publicvoidSend(shortdata){byte[]longth=TypeConvert.getBytes(data,true);mSocket.Send(longth);}publicvoidSend(longdata){byte[]longth=TypeConvert.getBytes(data,true);mSocket.Send(longth);}publicvoidSend(intdata){byte[]longth=TypeConvert.getBytes(data,true);mSocket.Send(longth);}publicvoidSend(stringdata){byte[]longth=Encoding.UTF8.GetBytes(data);Send(longth.Length);mSocket.Send(longth);}publicshortReceiveShort(){byte[]recvBytes=newbyte[2];mSocket.Receive(recvBytes,2,0);//从服务器端接受返回信息shortdata=TypeConvert.getShort(recvBytes,true);returndata;}publicintReceiveInt(){byte[]recvBytes=newbyte[4];mSocket.Receive(recvBytes,4,0);//从服务器端接受返回信息intdata=TypeConvert.getInt(recvBytes,true);returndata;}publiclongReceiveLong(){byte[]recvBytes=newbyte[8];mSocket.Receive(recvBytes,8,0);//从服务器端接受返回信息longdata=TypeConvert.getLong(recvBytes,true);returndata;}publicStringReceiveString(){intlength=ReceiveInt();MonoBehaviour.print("Stringlen="+length);byte[]recvBytes=newbyte[length];mSocket.Receive(recvBytes,length,0);//从服务器端接受返回信息Stringdata=Encoding.UTF8.GetString(recvBytes);returndata;}}}namespace LSocket.Net { /** * * @author feng侠,qq:313785443 * @date 2010-12-23 * */ // 描 述:封装c# socket大发888网上投注凭你现在的实力 传输协议 using UnityEngine; using System; using System.Net.Sockets; using System.Net; using System.Collections; using System.Text; using System.Threading;using LSocket.Type; using LSocket.cmd; class SocketThread { UnitySocket socket; SocketDemo demo; int idx; public SocketThread(UnitySocket socket, SocketDemo demo, int idx) { this.socket = socket; this.demo = demo; this.idx = idx; } public void run() { while (true) { try { String s = socket.ReceiveString(); demo.textAreaString[idx * 3] = demo.textAreaString[idx * 3 + 1]; demo.textAreaString[idx * 3 + 1] = demo.textAreaString[idx * 3 + 2]; demo.textAreaString[idx * 3 + 2] = s; MonoBehaviour.print(s + " " + idx); } catch (Exception e) { MonoBehaviour.print(e.ToString()); socket.t.Abort(); } } } } public class UnitySocket { public Socket mSocket = null; public Thread t=null; private SocketThread st=null; public SocketDemo demo=null; public UnitySocket() { } public void SocketConnection(string LocalIP, int LocalPort,SocketDemo demo,int idx) { this.demo=demo;mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { IPAddress ip = IPAddress.Parse(LocalIP); IPEndPoint ipe = new IPEndPoint(ip, LocalPort); mSocket.Connect(ipe); st =new SocketThread(this, demo, idx); t = new Thread(new ThreadStart(st.run)); t.Start(); } catch (Exception e) { MonoBehaviour.print(e.ToString()); } } public void close(){ mSocket.Close(0); mSocket=null; } public void DoLogin(String userName){ try { Send(CommandID.LOGIN); Send(userName); }catch(Exception e){ MonoBehaviour.print(e.ToString()); } } public void Send(float data){ byte[] longth = TypeConvert.getBytes(data, true); mSocket.Send(longth); } public float ReceiveFloat() { byte[] recvBytes = new byte[4]; mSocket.Receive(recvBytes, 4, 0);//从服务器端接受返回信息 float data = TypeConvert.getFloat(recvBytes, true); return data; } public void Send(short data) { byte[] longth=TypeConvert.getBytes(data,true); mSocket.Send(longth);} public void Send(long data) { byte[] longth=TypeConvert.getBytes(data,true); mSocket.Send(longth); } public void Send(int data) { byte[] longth=TypeConvert.getBytes(data,true); mSocket.Send(longth); } public void Send(string data) { byte[] longth=Encoding.UTF8.GetBytes(data); Send(longth.Length);mSocket.Send(longth); } public short ReceiveShort() { byte[] recvBytes = new byte[2]; mSocket.Receive(recvBytes,2,0);//从服务器端接受返回信息 short data=TypeConvert.getShort(recvBytes,true); return data; } public int ReceiveInt() { byte[] recvBytes = new byte[4]; mSocket.Receive(recvBytes,4,0);//从服务器端接受返回信息 int data=TypeConvert.getInt(recvBytes,true); return data; } public long ReceiveLong() { byte[] recvBytes = new byte[8]; mSocket.Receive(recvBytes,8,0);//从服务器端接受返回信息 long data=TypeConvert.getLong(recvBytes,true); return data; } public String ReceiveString() { int length = ReceiveInt(); MonoBehaviour.print("Stringlen="+length); byte[] recvBytes = new byte[length]; mSocket.Receive(recvBytes,length,0);//从服务器端接受返回信息 String data = Encoding.UTF8.GetString(recvBytes); return data; } }} [csharp] view plaincopyprint?namespaceLSocket.Type{usingUnityEngine;usingSystem.Collections;publicclassTypeConvert{publicTypeConvert(){}publicstaticbyte[]getBytes(floats,boolasc){intbuf=(int)(s*100);returngetBytes(buf,asc);}publicstaticfloatgetFloat(byte[]buf,boolasc){inti=getInt(buf,asc);floats=(float)i;returns/100;}publicstaticbyte[]getBytes(shorts,boolasc){byte[]buf=newbyte[2];if(asc){for(inti=buf.Length-1;i>=0;i--){buf[i]=(byte)(s&0x00ff);s>>=8;}}else{for(inti=0;i<buf.Length;i++){buf[i]=(byte)(s&0x00ff);s>>=8;}}returnbuf;}publicstaticbyte[]getBytes(ints,boolasc){byte[]buf=newbyte[4];if(asc)for(inti=buf.Length-1;i>=0;i--){buf[i]=(byte)(s&0x000000ff);s>>=8;}elsefor(inti=0;i<buf.Length;i++){buf[i]=(byte)(s&0x000000ff);s>>=8;}returnbuf;}publicstaticbyte[]getBytes(longs,boolasc){byte[]buf=newbyte[8];if(asc)for(inti=buf.Length-1;i>=0;i--){buf[i]=(byte)(s&0x00000000000000ff);s>>=8;}elsefor(inti=0;i<buf.Length;i++){buf[i]=(byte)(s&0x00000000000000ff);s>>=8;}returnbuf;}publicstaticshortgetShort(byte[]buf,boolasc){if(buf==null){//thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.Length>2){//thrownewIllegalArgumentException("bytearraysize>2!");}shortr=0;if(!asc)for(inti=buf.Length-1;i>=0;i--){r<<=8;r|=(short)(buf[i]&0x00ff);}elsefor(inti=0;i<buf.Length;i++){r<<=8;r|=(short)(buf[i]&0x00ff);}returnr;}publicstaticintgetInt(byte[]buf,boolasc){if(buf==null){//thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.Length>4){//thrownewIllegalArgumentException("bytearraysize>4!");}intr=0;if(!asc)for(inti=buf.Length-1;i>=0;i--){r<<=8;r|=(buf[i]&0x000000ff);}elsefor(inti=0;i<buf.Length;i++){r<<=8;r|=(buf[i]&0x000000ff);}returnr;}publicstaticlonggetLong(byte[]buf,boolasc){if(buf==null){//thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.Length>8){//thrownewIllegalArgumentException("bytearraysize>8!");}longr=0;if(!asc)for(inti=buf.Length-1;i>=0;i--){r<<=8;r|=(buf[i]&0x00000000000000ff);}elsefor(inti=0;i<buf.Length;i++){r<<=8;r|=(buf[i]&0x00000000000000ff);}returnr;}}}namespace LSocket.Type{ using UnityEngine; using System.Collections; public class TypeConvert { public TypeConvert() { } public static byte[] getBytes(float s,bool asc){ int buf = (int)(s * 100); return getBytes(buf,asc); } public static float getFloat(byte[] buf,bool asc){ int i=getInt(buf,asc); float s=(float)i; return s/100; } public static byte[] getBytes(short s, bool asc) { byte[] buf = new byte[2]; if (asc) { for (int i = buf.Length - 1; i >= 0; i--) { buf[i] = (byte)(s & 0x00ff); s >>= 8; } } else { for (int i = 0; i < buf.Length; i++) { buf[i] = (byte)(s & 0x00ff); s >>= 8; } } return buf; } public static byte[] getBytes(int s, bool asc) { byte[] buf = new byte[4]; if (asc) for (int i = buf.Length - 1; i >= 0; i--) { buf[i] = (byte)(s & 0x000000ff); s >>= 8; } else for (int i = 0; i < buf.Length; i++) { buf[i] = (byte)(s & 0x000000ff); s >>= 8; } return buf; } public static byte[] getBytes(long s, bool asc) { byte[] buf = new byte[8]; if (asc) for (int i = buf.Length - 1; i >= 0; i--) { buf[i] = (byte)(s & 0x00000000000000ff); s >>= 8; } else for (int i = 0; i < buf.Length; i++) { buf[i] = (byte)(s & 0x00000000000000ff); s >>= 8; } return buf; } public static short getShort(byte[] buf, bool asc) { if (buf == null) { //throw new IllegalArgumentException("byte array is null!"); } if (buf.Length > 2) { //throw new IllegalArgumentException("byte array size > 2 !"); } short r = 0; if (!asc) for (int i = buf.Length - 1; i >= 0; i--) { r <<= 8; r |= (short)(buf[i] & 0x00ff); } else for (int i = 0; i < buf.Length; i++) { r <<= 8; r |= (short)(buf[i] & 0x00ff); } return r; } public static int getInt(byte[] buf, bool asc) { if (buf == null) { // throw new IllegalArgumentException("byte array is null!"); } if (buf.Length > 4) { //throw new IllegalArgumentException("byte array size > 4 !"); } int r = 0; if (!asc) for (int i = buf.Length - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0x000000ff); } else for (int i = 0; i < buf.Length; i++) { r <<= 8; r |= (buf[i] & 0x000000ff); } return r; } public static long getLong(byte[] buf, bool asc) { if (buf == null) { //throw new IllegalArgumentException("byte array is null!"); } if (buf.Length > 8) { //throw new IllegalArgumentException("byte array size > 8 !"); } long r = 0; if (!asc) for (int i = buf.Length - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0x00000000000000ff); } else for (int i = 0; i < buf.Length; i++) { r <<= 8; r |= (buf[i] & 0x00000000000000ff); } return r; } }}[csharp] view plaincopyprint?namespaceLSocket.cmd{publicclassCommandID{/**登陆消息命令**/publicstaticintLOGIN=1001;}}namespace LSocket.cmd{ public class CommandID { /** 登陆消息命令 **/ public static int LOGIN = 1001; }}服务器端代码 Java:[java] view plaincopyprint?packagecom.unity.socket;importjava.net.ServerSocket;importjava.net.Socket;importjava.util.HashMap;publicclassSocketServer{privateHashMap<String,User>userMap;publicSocketServer(){userMap=newHashMap<String,User>();}publicstaticvoidmain(String[]args){newSocketServer().startServer();}publicvoidstartServer(){try{ServerSocketserverSocket=newServerSocket(10000);System.out.println("服务器开启");while(true){Socketsocket=serverSocket.accept();System.out.println("有用户登陆进来了");newUserThread(socket,userMap).start();}}catch(Exceptione){System.out.println("服务器出现异常!"+e);}}}package com.unity.socket;import java.net.ServerSocket;import java.net.Socket;import java.util.HashMap;public class SocketServer { private HashMap<String,User> userMap; public SocketServer(){ userMap=new HashMap<String, User>(); } public static void main(String[] args){ new SocketServer().startServer(); } public void startServer(){try{ServerSocket serverSocket = new ServerSocket(10000);System.out.println("服务器开启"); while (true){ Socket socket = serverSocket.accept(); System.out.println("有用户登陆进来了"); new UserThread(socket,userMap).start(); } }catch (Exception e){ System.out.println("服务器出现异常!" + e); } }}[java] view plaincopyprint?packagecom.unity.socket;importjava.net.Socket;publicclassUser{privateStringname;privateSocketsocket;publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicSocketgetSocket(){returnsocket;}publicvoidsetSocket(Socketsocket){this.socket=socket;}}package com.unity.socket;import java.net.Socket;public class User { private String name; private Socket socket; public String getName() { return name; } public void setName(String name) { this.name = name; } public Socket getSocket() { return socket; } public void setSocket(Socket socket) { this.socket = socket; }}[java] view plaincopyprint?packagecom.unity.socket;importjava.io.*;importjava.net.Socket;importjava.util.Iterator;importjava.io.ByteArrayOutputStream;importjava.io.DataOutputStream;importjava.util.HashMap;publicclassUserThreadextendsThread{/**错误消息命令**/publicstaticfinalintERROR=0;/**登陆消息命令**/publicstaticfinalintLOGIN=1001;privateSocketsocket;privateHashMap<String,User>userMap;privateUseruser;privateByteArrayOutputStreambyteOutput;privateDataOutputStreamoutput;privateDataInputStreaminput;publicUserThread(Socketsocket,HashMap<String,User>userMap){this.socket=socket;this.userMap=userMap;}//重新初始化2个新的output privatevoidinitOutput(){byteOutput=newByteArrayOutputStream();output=newDataOutputStream(byteOutput);}publicvoidsendAllUser(byte[]bytes)throwsException{for(Iterator<User>it=userMap.values().iterator();it.hasNext();){sendMessage(it.next().getSocket(),bytes);}}publicvoidsendMessage(Socketsocket,byte[]bytes)throwsException{DataOutputStreamdataOutput=newDataOutputStream(socket.getOutputStream());dataOutput.write(bytes);dataOutput.flush();}publicshortreadShort()throwsIOException{byte[]buf=newbyte[2];input.read(buf);returnConvertType.getShort(buf,true);}publicintreadInt()throwsIOException{byte[]buf=newbyte[4];input.read(buf);returnConvertType.getInt(buf,true);}publiclongreadLong()throwsIOException{byte[]buf=newbyte[8];input.read(buf);returnConvertType.getLong(buf,true);}publicfloatreadFloat()throwsIOException{byte[]buf=newbyte[4];input.read(buf);returnConvertType.getFloat(buf,true);}publicStringreadString()throwsIOException{intlength=readInt();byte[]buf=newbyte[length];input.read(buf);returnnewString(buf);}publicvoidrun(){try{input=newDataInputStream(socket.getInputStream());while(true){intcmd=0;cmd=readInt();System.out.println("命令号:"+cmd);if(cmd==ERROR){//收空包userMap.remove(user.getName());Messagemsg=newMessage();msg.writeString(user.getName()+"离开");System.out.println(user.getName()+"离开");try{sendAllUser(msg.getBuff().array());}catch(Exceptionex){System.out.println("sendAllUserErr:"+ex.toString());}break;}switch(cmd){caseLOGIN:System.out.println("读取用户名");StringuserName=readString();user=newUser();user.setName(userName);user.setSocket(socket);System.out.println(userName);if(userMap.containsKey(userName)){Messagemsg=newMessage();msg.writeString("昵称重复");sendMessage(socket,msg.getBuff().array());msg.clear();msg=null;}else{System.out.println("有新用户进入:"+userName);userMap.put(userName,user);initOutput();Messagemsg=newMessage();msg.writeString("连接成功");sendMessage(socket,msg.getBuff().array());msg.clear();msg=null;}break;}}}catch(Exceptione){e.printStackTrace();userMap.remove(user.getName());Messagemsg=newMessage();msg.writeString(user.getName()+"离开");System.out.println(user.getName()+"离开");try{sendAllUser(msg.getBuff().array());}catch(Exceptionex){System.out.println("sendAllUserErr:"+ex.toString());}}}}package com.unity.socket;import java.io.*;import java.net.Socket;import java.util.Iterator;import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import java.util.HashMap;public class UserThread extends Thread{ /** 错误消息命令 **/public static final int ERROR = 0;/** 登陆消息命令 **/public static final int LOGIN = 1001; private Socket socket; private HashMap<String,User> userMap; private User user; private ByteArrayOutputStream byteOutput; private DataOutputStream output; private DataInputStream input; public UserThread(Socket socket,HashMap<String,User> userMap){ this.socket=socket; this.userMap=userMap; } //重新初始化2个新的outputprivate void initOutput(){byteOutput = new ByteArrayOutputStream();output = new DataOutputStream(byteOutput);} public void sendAllUser(byte[] bytes) throws Exception{for(Iterator<User> it = userMap.values().iterator(); it.hasNext();){sendMessage(it.next().getSocket(),bytes);}} public void sendMessage(Socket socket,byte[] bytes) throws Exception{DataOutputStream dataOutput = new DataOutputStream(socket.getOutputStream());dataOutput.write(bytes);dataOutput.flush();} public short readShort()throws IOException{ byte[] buf=new byte[2]; input.read(buf); return ConvertType.getShort(buf,true); } public int readInt()throws IOException{ byte[] buf=new byte[4]; input.read(buf); return ConvertType.getInt(buf, true); } public long readLong()throws IOException{ byte[] buf=new byte[8]; input.read(buf); return ConvertType.getLong(buf, true); } public float readFloat()throws IOException{ byte[] buf=new byte[4]; input.read(buf); return ConvertType.getFloat(buf, true); } public String readString()throws IOException{ int length=readInt(); byte[] buf=new byte[length]; input.read(buf); return new String(buf); } public void run(){ try{ input = new DataInputStream(socket.getInputStream()) ; while (true){ int cmd=0; cmd=readInt(); System.out.println("命令号:"+cmd); if(cmd==ERROR){ //收空包 userMap.remove(user.getName()); Message msg=new Message(); msg.writeString(user.getName()+" 离开"); System.out.println(user.getName()+" 离开"); try{ sendAllUser(msg.getBuff().array()); }catch (Exception ex){ System.out.println("sendAllUserErr: "+ex.toString()); } break; } switch (cmd){ case LOGIN: System.out.println("读取用户名"); String userName = readString(); user = new User(); user.setName(userName); user.setSocket(socket); System.out.println(userName); if(userMap.containsKey(userName)) { Message msg=new Message(); msg.writeString("昵称重复");sendMessage(socket,msg.getBuff().array()); msg.clear(); msg=null; }else{ System.out.println("有新用户进入:" + userName);userMap.put(userName, user);initOutput(); Message msg=new Message(); msg.writeString("连接成功");sendMessage(socket,msg.getBuff().array()); msg.clear(); msg=null; } break; } } }catch (Exception e){ e.printStackTrace(); userMap.remove(user.getName()); Message msg=new Message(); msg.writeString(user.getName()+" 离开"); System.out.println(user.getName()+" 离开"); try{ sendAllUser(msg.getBuff().array()); }catch (Exception ex){ System.out.println("sendAllUserErr: "+ex.toString()); } } }}[java] view plaincopyprint?packagecom.unity.socket;importjava.nio.ByteBuffer;importcom.unity.socket.ConvertType;publicclassMessage{privateByteBufferbuf;publicMessage(){buf=ByteBuffer.allocate(0);}publicByteBuffergetBuff(){returnbuf;}publicvoidclear(){buf.clear();}publicvoidaddSize(intlen){ByteBuffertmpbuf=ByteBuffer.allocate(buf.capacity()+len);buf=null;buf=tmpbuf;}publicvoidwriteByte(byteb){addSize(1);buf.put(b);}publicvoidwrite(byte[]b){addSize(b.length);buf.put(b);}publicvoidwriteShort(shortb){addSize(2);buf.put(ConvertType.getBytes(b,true));}publicvoidwriteInt(intb){addSize(4);buf.put(ConvertType.getBytes(b,true));}publicvoidwriteLong(longb){addSize(8);buf.put(ConvertType.getBytes(b,true));}publicvoidwriteFloat(floatb){addSize(4);buf.put(ConvertType.getBytes(b,true));}publicvoidwriteString(Strings){byte[]b=newbyte[200];b=s.getBytes();addSize(4+b.length);buf.put(ConvertType.getBytes(b.length,true));buf.put(s.getBytes());}}package com.unity.socket;import java.nio.ByteBuffer;import com.unity.socket.ConvertType;public class Message { private ByteBuffer buf; public Message(){ buf=ByteBuffer.allocate(0); } public ByteBuffer getBuff(){ return buf; } public void clear(){ buf.clear(); } public void addSize(int len){ ByteBuffer tmpbuf=ByteBuffer.allocate(buf.capacity()+len); buf=null; buf=tmpbuf; } public void writeByte(byte b){ addSize(1); buf.put(b); } public void write(byte[] b){ addSize(b.length); buf.put(b); } public void writeShort(short b){ addSize(2); buf.put(ConvertType.getBytes(b,true)); } public void writeInt(int b){ addSize(4); buf.put(ConvertType.getBytes(b,true)); } public void writeLong(long b){ addSize(8); buf.put(ConvertType.getBytes(b,true)); } public void writeFloat(float b){ addSize(4); buf.put(ConvertType.getBytes(b,true)) ; } public void writeString(String s){ byte[] b= new byte[200]; b=s.getBytes(); addSize(4+b.length); buf.put(ConvertType.getBytes(b.length,true)); buf.put(s.getBytes()); }}[java] view plaincopyprint?packagecom.unity.socket;publicclassConvertType{publicConvertType(){}publicfinalstaticbyte[]getBytes(floats,booleanasc){intbuf=(int)(s*100);returngetBytes(buf,asc);}publicfinalstaticfloatgetFloat(byte[]buf,booleanasc){inti=getInt(buf,asc);floats=(float)i;returns/100;}publicfinalstaticbyte[]getBytes(shorts,booleanasc){byte[]buf=newbyte[2];if(asc){for(inti=buf.length-1;i>=0;i--){buf[i]=(byte)(s&0x00ff);s>>=8;}}else{for(inti=0;i<buf.length;i++){buf[i]=(byte)(s&0x00ff);s>>=8;}}returnbuf;}publicfinalstaticbyte[]getBytes(ints,booleanasc){byte[]buf=newbyte[4];if(asc)for(inti=buf.length-1;i>=0;i--){buf[i]=(byte)(s&0x000000ff);s>>=8;}elsefor(inti=0;i<buf.length;i++){buf[i]=(byte)(s&0x000000ff);s>>=8;}returnbuf;}publicfinalstaticbyte[]getBytes(longs,booleanasc){byte[]buf=newbyte[8];if(asc)for(inti=buf.length-1;i>=0;i--){buf[i]=(byte)(s&0x00000000000000ff);s>>=8;}elsefor(inti=0;i<buf.length;i++){buf[i]=(byte)(s&0x00000000000000ff);s>>=8;}returnbuf;}publicfinalstaticshortgetShort(byte[]buf,booleanasc){if(buf==null){thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.length>2){thrownewIllegalArgumentException("bytearraysize>2!");}shortr=0;if(!asc)for(inti=buf.length-1;i>=0;i--){r<<=8;r|=(buf[i]&0x00ff);}elsefor(inti=0;i<buf.length;i++){r<<=8;r|=(buf[i]&0x00ff);}returnr;}publicfinalstaticintgetInt(byte[]buf,booleanasc){if(buf==null){thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.length>4){thrownewIllegalArgumentException("bytearraysize>4!");}intr=0;if(!asc)for(inti=buf.length-1;i>=0;i--){r<<=8;r|=(buf[i]&0x000000ff);}elsefor(inti=0;i<buf.length;i++){r<<=8;r|=(buf[i]&0x000000ff);}returnr;}publicfinalstaticlonggetLong(byte[]buf,booleanasc){if(buf==null){thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.length>8){thrownewIllegalArgumentException("bytearraysize>8!");}longr=0;if(!asc)for(inti=buf.length-1;i>=0;i--){r<<=8;r|=(buf[i]&0x00000000000000ff);}elsefor(inti=0;i<buf.length;i++){r<<=8;r|=(buf[i]&0x00000000000000ff);}returnr;}}package com.unity.socket;public class ConvertType {public ConvertType(){} public final static byte[] getBytes(float s,boolean asc){ int buf=(int)(s*100); return getBytes(buf,asc); } public final static float getFloat(byte[] buf,boolean asc){ int i=getInt(buf,asc); float s=(float)i; return s/100; }public final static byte[] getBytes(short s, boolean asc){ byte[] buf = new byte[2]; if (asc) { for (int i = buf.length - 1; i >= 0; i--) { buf[i] = (byte) (s & 0x00ff); s >>= 8; } } else { for (int i = 0; i < buf.length; i++) { buf[i] = (byte) (s & 0x00ff); s >>= 8; } } return buf; } public final static byte[] getBytes(int s, boolean asc) { byte[] buf = new byte[4]; if (asc) for (int i = buf.length - 1; i >= 0; i--) { buf[i] = (byte) (s & 0x000000ff); s >>= 8; } else for (int i = 0; i < buf.length; i++) { buf[i] = (byte) (s & 0x000000ff); s >>= 8; } return buf; } public final static byte[] getBytes(long s, boolean asc) { byte[] buf = new byte[8]; if (asc) for (int i = buf.length - 1; i >= 0; i--) { buf[i] = (byte) (s & 0x00000000000000ff); s >>= 8; } else for (int i = 0; i < buf.length; i++) { buf[i] = (byte) (s & 0x00000000000000ff); s >>= 8; } return buf; } public final static short getShort(byte[] buf, boolean asc) { if (buf == null) { throw new IllegalArgumentException("byte array is null!"); } if (buf.length > 2) { throw new IllegalArgumentException("byte array size > 2 !"); } short r = 0; if (!asc) for (int i = buf.length - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0x00ff); } else for (int i = 0; i < buf.length; i++) { r <<= 8; r |= (buf[i] & 0x00ff); } return r; } public final static int getInt(byte[] buf, boolean asc) { if (buf == null) { throw new IllegalArgumentException("byte array is null!"); } if (buf.length > 4) { throw new IllegalArgumentException("byte array size > 4 !"); } int r = 0; if (!asc) for (int i = buf.length - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0x000000ff); } else for (int i = 0; i < buf.length; i++) { r <<= 8; r |= (buf[i] & 0x000000ff); } return r; } public final static long getLong(byte[] buf, boolean asc) { if (buf == null) { throw new IllegalArgumentException("byte array is null!"); } if (buf.length > 8) { throw new IllegalArgumentException("byte array size > 8 !"); } long r = 0; if (!asc) for (int i = buf.length - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0x00000000000000ff); } else for (int i = 0; i < buf.length; i++) { r <<= 8; r |= (buf[i] & 0x00000000000000ff); } return r; }}很简单的demo,有一定的可扩展性,需要工程的可以下载来看,下载链接http://download.csdn.net/detail/genius840215/4187126 接下来看一下ItemAnimator 大发888投注网更是我族的至尊魔器

如果按母亲的标准李雷肯定排除在相亲名单外了,而她想给他一个机会

PostQueuedCompletionStatus()函数的原型是这样定义的: BOOL WINAPI PostQueuedCompletionStatus( __in HANDLE CompletionPort, __in DWORD dwNumberOfBytesTransferred, __in ULONG_PTR dwCompletionKey, __in_opt LPOVERLAPPED lpOverlapped ); 大发888网上投注凭你现在的实力 可以看到,这个函数的参数几乎和GetQueuedCompletionStatus()的一模一样,都是需要把大发888网上投注凭你现在的实力 建立的完成端口传进去,然后后面的三个参数是 传输字节数、结构体参数、重叠结构的指针. 注意,这里也有一个很神奇的事情,正常情况下,GetQueuedCompletionStatus()获取回来的参数本来是应该是系统帮大发888网上投注凭你现在的实力 填充的,或者是在绑定完成端口时就有的,但是大发888网上投注凭你现在的实力 这里却可以直接使用PostQueuedCompletionStatus()直接将后面三个参数传递给GetQueuedCompletionStatus(),这样就非常方便了 大发888娱乐场介绍熟悉又陌生

否则,分配器将进入忙等待状态,从一个线程到另一个线程大发888网上投注凭你现在的实力 停的循环判断是否有大发888网上投注凭你现在的实力 可获取 大发888娱乐场怎么样随即压缩在压缩

大发888网上投注凭你现在的实力

2. 过滤组件扫描在如何扫描来获得候选Bean方面,<context:component-scan>元素非常灵活

唯一的区别就是 getSparseHistogram 返回的是个稀疏矩阵 大发888娱乐城百家_乐注册随即便沉默不语了

代码都比较好理解,就大发888网上投注凭你现在的实力 赘述了

$.parser.onComplete,这个是在所有组件解析完成后执行的事件 大发888游戏下载收获听完魔神的话

下面是一个使用例子代码:<span style="font-size:14px;">#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/core/core.hpp"#include <string>#include <iostream>using namespace cv;using namespace std;class Data0{ public: int a; vector<Mat> mat;};class Data{ public: string name; vector<Mat> imageset; vector<Data0> data0; //该类的写大发888网上投注凭你现在的实力 函数, 由于类的结构opencv大发888网上投注凭你现在的实力 知道,所以需要大发888网上投注凭你现在的实力 写相应的代码,对于已知的大发888网上投注凭你现在的实力 类型,如Mat、vector、int等只需直接利用 //操作符>>或者<<

p> 工程目录: 下面上代码:客户端代码:[csharp] view plaincopyprint?usingUnityEngine;usingSystem;usingSystem.Collections;usingLSocket.Net;usingLSocket.Type;usingLSocket.cmd;publicclassSocketDemo:MonoBehaviour{publicUnitySocket[]socket;publicString[]textAreaString;publicString[]textFieldString;publicGUISkinmySkin;//Usethisforinitialization voidStart(){socket=newUnitySocket[4];textAreaString=newString[12];for(inti=0;i<12;i++){textAreaString[i]="";}textFieldString=newString[4];for(inti=0;i<4;i++){textFieldString[i]="";}}//UpdateiscalledonceperframevoidUpdate(){}voidOnGUI(){GUI.skin=mySkin;for(inti=0;i<4;i++){Strings=textAreaString[i*3]+"\n"+textAreaString[i*3+1]+"\n"+textAreaString[i*3+2];GUI.TextArea(newRect(i%2*Screen.width/2,i/2*(Screen.height/2)+50,100,60),s);textFieldString[i]=GUI.TextField(newRect(i%2*Screen.width/2+50,i/2*(Screen.height/2),100,20),textFieldString[i]);if(GUI.Button(newRect(i%2*Screen.width/2,i/2*(Screen.height/2),40,20),"连接")){socket[i]=null;socket[i]=newUnitySocket();socket[i].SocketConnection("192.168.0.8",10000,this,i);socket[i].DoLogin(textFieldString[i]);}elseif(GUI.Button(newRect(i%2*Screen.width/2,i/2*(Screen.height/2)+25,40,20),"关闭")){if(socket[i]!=null){socket[i].close();socket[i]=null;}}}if(GUI.Button(newRect(Screen.width-60,Screen.height-30,60,30),"退出")){Application.Quit();}}} using UnityEngine; using System; using System.Collections; using LSocket.Net; using LSocket.Type; using LSocket.cmd; public class SocketDemo : MonoBehaviour { public UnitySocket[] socket; public String[] textAreaString; public String[] textFieldString; public GUISkin mySkin; // Use this for initialization void Start() { socket = new UnitySocket[4]; textAreaString = new String[12]; for (int i = 0; i < 12; i++) { textAreaString[i] = ""; } textFieldString = new String[4]; for(int i=0;i<4;i++){ textFieldString[i] = ""; } } // Update is called once per frame void Update() { } void OnGUI() { GUI.skin = mySkin; for (int i = 0; i < 4; i++) { String s = textAreaString[i * 3] + "\n" + textAreaString[i * 3 + 1] + "\n" + textAreaString[i * 3 + 2]; GUI.TextArea(new Rect(i % 2 * Screen.width / 2, i / 2 * (Screen.height / 2) + 50, 100, 60), s); textFieldString[i] = GUI.TextField(new Rect(i % 2 * Screen.width / 2+50, i / 2 * (Screen.height / 2), 100, 20), textFieldString[i]); if (GUI.Button(new Rect(i % 2 * Screen.width / 2, i / 2 * (Screen.height / 2), 40, 20), "连接")) { socket[i] = null; socket[i] = new UnitySocket(); socket[i].SocketConnection("192.168.0.8", 10000, this, i); socket[i].DoLogin(textFieldString[i]); } else if (GUI.Button(new Rect(i % 2 * Screen.width / 2, i / 2 *( Screen.height / 2) + 25, 40, 20), "关闭")) { if (socket[i] != null) { socket[i].close(); socket[i] = null; } } } if (GUI.Button(new Rect(Screen.width - 60, Screen.height - 30, 60, 30), "退出")) { Application.Quit(); } } }[csharp] view plaincopyprint?namespaceLSocket.Net{/****@authorfeng侠,qq:313785443*@date2010-12-23**///描述:封装c#socket大发888网上投注凭你现在的实力 传输协议usingUnityEngine;usingSystem;usingSystem.Net.Sockets;usingSystem.Net;usingSystem.Collections;usingSystem.Text;usingSystem.Threading;usingLSocket.Type;usingLSocket.cmd;classSocketThread{UnitySocketsocket;SocketDemodemo;intidx;publicSocketThread(UnitySocketsocket,SocketDemodemo,intidx){this.socket=socket;this.demo=demo;this.idx=idx;}publicvoidrun(){while(true){try{Strings=socket.ReceiveString();demo.textAreaString[idx*3]=demo.textAreaString[idx*3+1];demo.textAreaString[idx*3+1]=demo.textAreaString[idx*3+2];demo.textAreaString[idx*3+2]=s;MonoBehaviour.print(s+""+idx);}catch(Exceptione){MonoBehaviour.print(e.ToString());socket.t.Abort();}}}}publicclassUnitySocket{publicSocketmSocket=null;publicThreadt=null;privateSocketThreadst=null;publicSocketDemodemo=null;publicUnitySocket(){}publicvoidSocketConnection(stringLocalIP,intLocalPort,SocketDemodemo,intidx){this.demo=demo;mSocket=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);try{IPAddressip=IPAddress.Parse(LocalIP);IPEndPointipe=newIPEndPoint(ip,LocalPort);mSocket.Connect(ipe);st=newSocketThread(this,demo,idx);t=newThread(newThreadStart(st.run));t.Start();}catch(Exceptione){MonoBehaviour.print(e.ToString());}}publicvoidclose(){mSocket.Close(0);mSocket=null;}publicvoidDoLogin(StringuserName){try{Send(CommandID.LOGIN);Send(userName);}catch(Exceptione){MonoBehaviour.print(e.ToString());}}publicvoidSend(floatdata){byte[]longth=TypeConvert.getBytes(data,true);mSocket.Send(longth);}publicfloatReceiveFloat(){byte[]recvBytes=newbyte[4];mSocket.Receive(recvBytes,4,0);//从服务器端接受返回信息floatdata=TypeConvert.getFloat(recvBytes,true);returndata;}publicvoidSend(shortdata){byte[]longth=TypeConvert.getBytes(data,true);mSocket.Send(longth);}publicvoidSend(longdata){byte[]longth=TypeConvert.getBytes(data,true);mSocket.Send(longth);}publicvoidSend(intdata){byte[]longth=TypeConvert.getBytes(data,true);mSocket.Send(longth);}publicvoidSend(stringdata){byte[]longth=Encoding.UTF8.GetBytes(data);Send(longth.Length);mSocket.Send(longth);}publicshortReceiveShort(){byte[]recvBytes=newbyte[2];mSocket.Receive(recvBytes,2,0);//从服务器端接受返回信息shortdata=TypeConvert.getShort(recvBytes,true);returndata;}publicintReceiveInt(){byte[]recvBytes=newbyte[4];mSocket.Receive(recvBytes,4,0);//从服务器端接受返回信息intdata=TypeConvert.getInt(recvBytes,true);returndata;}publiclongReceiveLong(){byte[]recvBytes=newbyte[8];mSocket.Receive(recvBytes,8,0);//从服务器端接受返回信息longdata=TypeConvert.getLong(recvBytes,true);returndata;}publicStringReceiveString(){intlength=ReceiveInt();MonoBehaviour.print("Stringlen="+length);byte[]recvBytes=newbyte[length];mSocket.Receive(recvBytes,length,0);//从服务器端接受返回信息Stringdata=Encoding.UTF8.GetString(recvBytes);returndata;}}}namespace LSocket.Net { /** * * @author feng侠,qq:313785443 * @date 2010-12-23 * */ // 描 述:封装c# socket大发888网上投注凭你现在的实力 传输协议 using UnityEngine; using System; using System.Net.Sockets; using System.Net; using System.Collections; using System.Text; using System.Threading;using LSocket.Type; using LSocket.cmd; class SocketThread { UnitySocket socket; SocketDemo demo; int idx; public SocketThread(UnitySocket socket, SocketDemo demo, int idx) { this.socket = socket; this.demo = demo; this.idx = idx; } public void run() { while (true) { try { String s = socket.ReceiveString(); demo.textAreaString[idx * 3] = demo.textAreaString[idx * 3 + 1]; demo.textAreaString[idx * 3 + 1] = demo.textAreaString[idx * 3 + 2]; demo.textAreaString[idx * 3 + 2] = s; MonoBehaviour.print(s + " " + idx); } catch (Exception e) { MonoBehaviour.print(e.ToString()); socket.t.Abort(); } } } } public class UnitySocket { public Socket mSocket = null; public Thread t=null; private SocketThread st=null; public SocketDemo demo=null; public UnitySocket() { } public void SocketConnection(string LocalIP, int LocalPort,SocketDemo demo,int idx) { this.demo=demo;mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { IPAddress ip = IPAddress.Parse(LocalIP); IPEndPoint ipe = new IPEndPoint(ip, LocalPort); mSocket.Connect(ipe); st =new SocketThread(this, demo, idx); t = new Thread(new ThreadStart(st.run)); t.Start(); } catch (Exception e) { MonoBehaviour.print(e.ToString()); } } public void close(){ mSocket.Close(0); mSocket=null; } public void DoLogin(String userName){ try { Send(CommandID.LOGIN); Send(userName); }catch(Exception e){ MonoBehaviour.print(e.ToString()); } } public void Send(float data){ byte[] longth = TypeConvert.getBytes(data, true); mSocket.Send(longth); } public float ReceiveFloat() { byte[] recvBytes = new byte[4]; mSocket.Receive(recvBytes, 4, 0);//从服务器端接受返回信息 float data = TypeConvert.getFloat(recvBytes, true); return data; } public void Send(short data) { byte[] longth=TypeConvert.getBytes(data,true); mSocket.Send(longth);} public void Send(long data) { byte[] longth=TypeConvert.getBytes(data,true); mSocket.Send(longth); } public void Send(int data) { byte[] longth=TypeConvert.getBytes(data,true); mSocket.Send(longth); } public void Send(string data) { byte[] longth=Encoding.UTF8.GetBytes(data); Send(longth.Length);mSocket.Send(longth); } public short ReceiveShort() { byte[] recvBytes = new byte[2]; mSocket.Receive(recvBytes,2,0);//从服务器端接受返回信息 short data=TypeConvert.getShort(recvBytes,true); return data; } public int ReceiveInt() { byte[] recvBytes = new byte[4]; mSocket.Receive(recvBytes,4,0);//从服务器端接受返回信息 int data=TypeConvert.getInt(recvBytes,true); return data; } public long ReceiveLong() { byte[] recvBytes = new byte[8]; mSocket.Receive(recvBytes,8,0);//从服务器端接受返回信息 long data=TypeConvert.getLong(recvBytes,true); return data; } public String ReceiveString() { int length = ReceiveInt(); MonoBehaviour.print("Stringlen="+length); byte[] recvBytes = new byte[length]; mSocket.Receive(recvBytes,length,0);//从服务器端接受返回信息 String data = Encoding.UTF8.GetString(recvBytes); return data; } }} [csharp] view plaincopyprint?namespaceLSocket.Type{usingUnityEngine;usingSystem.Collections;publicclassTypeConvert{publicTypeConvert(){}publicstaticbyte[]getBytes(floats,boolasc){intbuf=(int)(s*100);returngetBytes(buf,asc);}publicstaticfloatgetFloat(byte[]buf,boolasc){inti=getInt(buf,asc);floats=(float)i;returns/100;}publicstaticbyte[]getBytes(shorts,boolasc){byte[]buf=newbyte[2];if(asc){for(inti=buf.Length-1;i>=0;i--){buf[i]=(byte)(s&0x00ff);s>>=8;}}else{for(inti=0;i<buf.Length;i++){buf[i]=(byte)(s&0x00ff);s>>=8;}}returnbuf;}publicstaticbyte[]getBytes(ints,boolasc){byte[]buf=newbyte[4];if(asc)for(inti=buf.Length-1;i>=0;i--){buf[i]=(byte)(s&0x000000ff);s>>=8;}elsefor(inti=0;i<buf.Length;i++){buf[i]=(byte)(s&0x000000ff);s>>=8;}returnbuf;}publicstaticbyte[]getBytes(longs,boolasc){byte[]buf=newbyte[8];if(asc)for(inti=buf.Length-1;i>=0;i--){buf[i]=(byte)(s&0x00000000000000ff);s>>=8;}elsefor(inti=0;i<buf.Length;i++){buf[i]=(byte)(s&0x00000000000000ff);s>>=8;}returnbuf;}publicstaticshortgetShort(byte[]buf,boolasc){if(buf==null){//thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.Length>2){//thrownewIllegalArgumentException("bytearraysize>2!");}shortr=0;if(!asc)for(inti=buf.Length-1;i>=0;i--){r<<=8;r|=(short)(buf[i]&0x00ff);}elsefor(inti=0;i<buf.Length;i++){r<<=8;r|=(short)(buf[i]&0x00ff);}returnr;}publicstaticintgetInt(byte[]buf,boolasc){if(buf==null){//thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.Length>4){//thrownewIllegalArgumentException("bytearraysize>4!");}intr=0;if(!asc)for(inti=buf.Length-1;i>=0;i--){r<<=8;r|=(buf[i]&0x000000ff);}elsefor(inti=0;i<buf.Length;i++){r<<=8;r|=(buf[i]&0x000000ff);}returnr;}publicstaticlonggetLong(byte[]buf,boolasc){if(buf==null){//thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.Length>8){//thrownewIllegalArgumentException("bytearraysize>8!");}longr=0;if(!asc)for(inti=buf.Length-1;i>=0;i--){r<<=8;r|=(buf[i]&0x00000000000000ff);}elsefor(inti=0;i<buf.Length;i++){r<<=8;r|=(buf[i]&0x00000000000000ff);}returnr;}}}namespace LSocket.Type{ using UnityEngine; using System.Collections; public class TypeConvert { public TypeConvert() { } public static byte[] getBytes(float s,bool asc){ int buf = (int)(s * 100); return getBytes(buf,asc); } public static float getFloat(byte[] buf,bool asc){ int i=getInt(buf,asc); float s=(float)i; return s/100; } public static byte[] getBytes(short s, bool asc) { byte[] buf = new byte[2]; if (asc) { for (int i = buf.Length - 1; i >= 0; i--) { buf[i] = (byte)(s & 0x00ff); s >>= 8; } } else { for (int i = 0; i < buf.Length; i++) { buf[i] = (byte)(s & 0x00ff); s >>= 8; } } return buf; } public static byte[] getBytes(int s, bool asc) { byte[] buf = new byte[4]; if (asc) for (int i = buf.Length - 1; i >= 0; i--) { buf[i] = (byte)(s & 0x000000ff); s >>= 8; } else for (int i = 0; i < buf.Length; i++) { buf[i] = (byte)(s & 0x000000ff); s >>= 8; } return buf; } public static byte[] getBytes(long s, bool asc) { byte[] buf = new byte[8]; if (asc) for (int i = buf.Length - 1; i >= 0; i--) { buf[i] = (byte)(s & 0x00000000000000ff); s >>= 8; } else for (int i = 0; i < buf.Length; i++) { buf[i] = (byte)(s & 0x00000000000000ff); s >>= 8; } return buf; } public static short getShort(byte[] buf, bool asc) { if (buf == null) { //throw new IllegalArgumentException("byte array is null!"); } if (buf.Length > 2) { //throw new IllegalArgumentException("byte array size > 2 !"); } short r = 0; if (!asc) for (int i = buf.Length - 1; i >= 0; i--) { r <<= 8; r |= (short)(buf[i] & 0x00ff); } else for (int i = 0; i < buf.Length; i++) { r <<= 8; r |= (short)(buf[i] & 0x00ff); } return r; } public static int getInt(byte[] buf, bool asc) { if (buf == null) { // throw new IllegalArgumentException("byte array is null!"); } if (buf.Length > 4) { //throw new IllegalArgumentException("byte array size > 4 !"); } int r = 0; if (!asc) for (int i = buf.Length - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0x000000ff); } else for (int i = 0; i < buf.Length; i++) { r <<= 8; r |= (buf[i] & 0x000000ff); } return r; } public static long getLong(byte[] buf, bool asc) { if (buf == null) { //throw new IllegalArgumentException("byte array is null!"); } if (buf.Length > 8) { //throw new IllegalArgumentException("byte array size > 8 !"); } long r = 0; if (!asc) for (int i = buf.Length - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0x00000000000000ff); } else for (int i = 0; i < buf.Length; i++) { r <<= 8; r |= (buf[i] & 0x00000000000000ff); } return r; } }}[csharp] view plaincopyprint?namespaceLSocket.cmd{publicclassCommandID{/**登陆消息命令**/publicstaticintLOGIN=1001;}}namespace LSocket.cmd{ public class CommandID { /** 登陆消息命令 **/ public static int LOGIN = 1001; }}服务器端代码 Java:[java] view plaincopyprint?packagecom.unity.socket;importjava.net.ServerSocket;importjava.net.Socket;importjava.util.HashMap;publicclassSocketServer{privateHashMap<String,User>userMap;publicSocketServer(){userMap=newHashMap<String,User>();}publicstaticvoidmain(String[]args){newSocketServer().startServer();}publicvoidstartServer(){try{ServerSocketserverSocket=newServerSocket(10000);System.out.println("服务器开启");while(true){Socketsocket=serverSocket.accept();System.out.println("有用户登陆进来了");newUserThread(socket,userMap).start();}}catch(Exceptione){System.out.println("服务器出现异常!"+e);}}}package com.unity.socket;import java.net.ServerSocket;import java.net.Socket;import java.util.HashMap;public class SocketServer { private HashMap<String,User> userMap; public SocketServer(){ userMap=new HashMap<String, User>(); } public static void main(String[] args){ new SocketServer().startServer(); } public void startServer(){try{ServerSocket serverSocket = new ServerSocket(10000);System.out.println("服务器开启"); while (true){ Socket socket = serverSocket.accept(); System.out.println("有用户登陆进来了"); new UserThread(socket,userMap).start(); } }catch (Exception e){ System.out.println("服务器出现异常!" + e); } }}[java] view plaincopyprint?packagecom.unity.socket;importjava.net.Socket;publicclassUser{privateStringname;privateSocketsocket;publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicSocketgetSocket(){returnsocket;}publicvoidsetSocket(Socketsocket){this.socket=socket;}}package com.unity.socket;import java.net.Socket;public class User { private String name; private Socket socket; public String getName() { return name; } public void setName(String name) { this.name = name; } public Socket getSocket() { return socket; } public void setSocket(Socket socket) { this.socket = socket; }}[java] view plaincopyprint?packagecom.unity.socket;importjava.io.*;importjava.net.Socket;importjava.util.Iterator;importjava.io.ByteArrayOutputStream;importjava.io.DataOutputStream;importjava.util.HashMap;publicclassUserThreadextendsThread{/**错误消息命令**/publicstaticfinalintERROR=0;/**登陆消息命令**/publicstaticfinalintLOGIN=1001;privateSocketsocket;privateHashMap<String,User>userMap;privateUseruser;privateByteArrayOutputStreambyteOutput;privateDataOutputStreamoutput;privateDataInputStreaminput;publicUserThread(Socketsocket,HashMap<String,User>userMap){this.socket=socket;this.userMap=userMap;}//重新初始化2个新的output privatevoidinitOutput(){byteOutput=newByteArrayOutputStream();output=newDataOutputStream(byteOutput);}publicvoidsendAllUser(byte[]bytes)throwsException{for(Iterator<User>it=userMap.values().iterator();it.hasNext();){sendMessage(it.next().getSocket(),bytes);}}publicvoidsendMessage(Socketsocket,byte[]bytes)throwsException{DataOutputStreamdataOutput=newDataOutputStream(socket.getOutputStream());dataOutput.write(bytes);dataOutput.flush();}publicshortreadShort()throwsIOException{byte[]buf=newbyte[2];input.read(buf);returnConvertType.getShort(buf,true);}publicintreadInt()throwsIOException{byte[]buf=newbyte[4];input.read(buf);returnConvertType.getInt(buf,true);}publiclongreadLong()throwsIOException{byte[]buf=newbyte[8];input.read(buf);returnConvertType.getLong(buf,true);}publicfloatreadFloat()throwsIOException{byte[]buf=newbyte[4];input.read(buf);returnConvertType.getFloat(buf,true);}publicStringreadString()throwsIOException{intlength=readInt();byte[]buf=newbyte[length];input.read(buf);returnnewString(buf);}publicvoidrun(){try{input=newDataInputStream(socket.getInputStream());while(true){intcmd=0;cmd=readInt();System.out.println("命令号:"+cmd);if(cmd==ERROR){//收空包userMap.remove(user.getName());Messagemsg=newMessage();msg.writeString(user.getName()+"离开");System.out.println(user.getName()+"离开");try{sendAllUser(msg.getBuff().array());}catch(Exceptionex){System.out.println("sendAllUserErr:"+ex.toString());}break;}switch(cmd){caseLOGIN:System.out.println("读取用户名");StringuserName=readString();user=newUser();user.setName(userName);user.setSocket(socket);System.out.println(userName);if(userMap.containsKey(userName)){Messagemsg=newMessage();msg.writeString("昵称重复");sendMessage(socket,msg.getBuff().array());msg.clear();msg=null;}else{System.out.println("有新用户进入:"+userName);userMap.put(userName,user);initOutput();Messagemsg=newMessage();msg.writeString("连接成功");sendMessage(socket,msg.getBuff().array());msg.clear();msg=null;}break;}}}catch(Exceptione){e.printStackTrace();userMap.remove(user.getName());Messagemsg=newMessage();msg.writeString(user.getName()+"离开");System.out.println(user.getName()+"离开");try{sendAllUser(msg.getBuff().array());}catch(Exceptionex){System.out.println("sendAllUserErr:"+ex.toString());}}}}package com.unity.socket;import java.io.*;import java.net.Socket;import java.util.Iterator;import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import java.util.HashMap;public class UserThread extends Thread{ /** 错误消息命令 **/public static final int ERROR = 0;/** 登陆消息命令 **/public static final int LOGIN = 1001; private Socket socket; private HashMap<String,User> userMap; private User user; private ByteArrayOutputStream byteOutput; private DataOutputStream output; private DataInputStream input; public UserThread(Socket socket,HashMap<String,User> userMap){ this.socket=socket; this.userMap=userMap; } //重新初始化2个新的outputprivate void initOutput(){byteOutput = new ByteArrayOutputStream();output = new DataOutputStream(byteOutput);} public void sendAllUser(byte[] bytes) throws Exception{for(Iterator<User> it = userMap.values().iterator(); it.hasNext();){sendMessage(it.next().getSocket(),bytes);}} public void sendMessage(Socket socket,byte[] bytes) throws Exception{DataOutputStream dataOutput = new DataOutputStream(socket.getOutputStream());dataOutput.write(bytes);dataOutput.flush();} public short readShort()throws IOException{ byte[] buf=new byte[2]; input.read(buf); return ConvertType.getShort(buf,true); } public int readInt()throws IOException{ byte[] buf=new byte[4]; input.read(buf); return ConvertType.getInt(buf, true); } public long readLong()throws IOException{ byte[] buf=new byte[8]; input.read(buf); return ConvertType.getLong(buf, true); } public float readFloat()throws IOException{ byte[] buf=new byte[4]; input.read(buf); return ConvertType.getFloat(buf, true); } public String readString()throws IOException{ int length=readInt(); byte[] buf=new byte[length]; input.read(buf); return new String(buf); } public void run(){ try{ input = new DataInputStream(socket.getInputStream()) ; while (true){ int cmd=0; cmd=readInt(); System.out.println("命令号:"+cmd); if(cmd==ERROR){ //收空包 userMap.remove(user.getName()); Message msg=new Message(); msg.writeString(user.getName()+" 离开"); System.out.println(user.getName()+" 离开"); try{ sendAllUser(msg.getBuff().array()); }catch (Exception ex){ System.out.println("sendAllUserErr: "+ex.toString()); } break; } switch (cmd){ case LOGIN: System.out.println("读取用户名"); String userName = readString(); user = new User(); user.setName(userName); user.setSocket(socket); System.out.println(userName); if(userMap.containsKey(userName)) { Message msg=new Message(); msg.writeString("昵称重复");sendMessage(socket,msg.getBuff().array()); msg.clear(); msg=null; }else{ System.out.println("有新用户进入:" + userName);userMap.put(userName, user);initOutput(); Message msg=new Message(); msg.writeString("连接成功");sendMessage(socket,msg.getBuff().array()); msg.clear(); msg=null; } break; } } }catch (Exception e){ e.printStackTrace(); userMap.remove(user.getName()); Message msg=new Message(); msg.writeString(user.getName()+" 离开"); System.out.println(user.getName()+" 离开"); try{ sendAllUser(msg.getBuff().array()); }catch (Exception ex){ System.out.println("sendAllUserErr: "+ex.toString()); } } }}[java] view plaincopyprint?packagecom.unity.socket;importjava.nio.ByteBuffer;importcom.unity.socket.ConvertType;publicclassMessage{privateByteBufferbuf;publicMessage(){buf=ByteBuffer.allocate(0);}publicByteBuffergetBuff(){returnbuf;}publicvoidclear(){buf.clear();}publicvoidaddSize(intlen){ByteBuffertmpbuf=ByteBuffer.allocate(buf.capacity()+len);buf=null;buf=tmpbuf;}publicvoidwriteByte(byteb){addSize(1);buf.put(b);}publicvoidwrite(byte[]b){addSize(b.length);buf.put(b);}publicvoidwriteShort(shortb){addSize(2);buf.put(ConvertType.getBytes(b,true));}publicvoidwriteInt(intb){addSize(4);buf.put(ConvertType.getBytes(b,true));}publicvoidwriteLong(longb){addSize(8);buf.put(ConvertType.getBytes(b,true));}publicvoidwriteFloat(floatb){addSize(4);buf.put(ConvertType.getBytes(b,true));}publicvoidwriteString(Strings){byte[]b=newbyte[200];b=s.getBytes();addSize(4+b.length);buf.put(ConvertType.getBytes(b.length,true));buf.put(s.getBytes());}}package com.unity.socket;import java.nio.ByteBuffer;import com.unity.socket.ConvertType;public class Message { private ByteBuffer buf; public Message(){ buf=ByteBuffer.allocate(0); } public ByteBuffer getBuff(){ return buf; } public void clear(){ buf.clear(); } public void addSize(int len){ ByteBuffer tmpbuf=ByteBuffer.allocate(buf.capacity()+len); buf=null; buf=tmpbuf; } public void writeByte(byte b){ addSize(1); buf.put(b); } public void write(byte[] b){ addSize(b.length); buf.put(b); } public void writeShort(short b){ addSize(2); buf.put(ConvertType.getBytes(b,true)); } public void writeInt(int b){ addSize(4); buf.put(ConvertType.getBytes(b,true)); } public void writeLong(long b){ addSize(8); buf.put(ConvertType.getBytes(b,true)); } public void writeFloat(float b){ addSize(4); buf.put(ConvertType.getBytes(b,true)) ; } public void writeString(String s){ byte[] b= new byte[200]; b=s.getBytes(); addSize(4+b.length); buf.put(ConvertType.getBytes(b.length,true)); buf.put(s.getBytes()); }}[java] view plaincopyprint?packagecom.unity.socket;publicclassConvertType{publicConvertType(){}publicfinalstaticbyte[]getBytes(floats,booleanasc){intbuf=(int)(s*100);returngetBytes(buf,asc);}publicfinalstaticfloatgetFloat(byte[]buf,booleanasc){inti=getInt(buf,asc);floats=(float)i;returns/100;}publicfinalstaticbyte[]getBytes(shorts,booleanasc){byte[]buf=newbyte[2];if(asc){for(inti=buf.length-1;i>=0;i--){buf[i]=(byte)(s&0x00ff);s>>=8;}}else{for(inti=0;i<buf.length;i++){buf[i]=(byte)(s&0x00ff);s>>=8;}}returnbuf;}publicfinalstaticbyte[]getBytes(ints,booleanasc){byte[]buf=newbyte[4];if(asc)for(inti=buf.length-1;i>=0;i--){buf[i]=(byte)(s&0x000000ff);s>>=8;}elsefor(inti=0;i<buf.length;i++){buf[i]=(byte)(s&0x000000ff);s>>=8;}returnbuf;}publicfinalstaticbyte[]getBytes(longs,booleanasc){byte[]buf=newbyte[8];if(asc)for(inti=buf.length-1;i>=0;i--){buf[i]=(byte)(s&0x00000000000000ff);s>>=8;}elsefor(inti=0;i<buf.length;i++){buf[i]=(byte)(s&0x00000000000000ff);s>>=8;}returnbuf;}publicfinalstaticshortgetShort(byte[]buf,booleanasc){if(buf==null){thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.length>2){thrownewIllegalArgumentException("bytearraysize>2!");}shortr=0;if(!asc)for(inti=buf.length-1;i>=0;i--){r<<=8;r|=(buf[i]&0x00ff);}elsefor(inti=0;i<buf.length;i++){r<<=8;r|=(buf[i]&0x00ff);}returnr;}publicfinalstaticintgetInt(byte[]buf,booleanasc){if(buf==null){thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.length>4){thrownewIllegalArgumentException("bytearraysize>4!");}intr=0;if(!asc)for(inti=buf.length-1;i>=0;i--){r<<=8;r|=(buf[i]&0x000000ff);}elsefor(inti=0;i<buf.length;i++){r<<=8;r|=(buf[i]&0x000000ff);}returnr;}publicfinalstaticlonggetLong(byte[]buf,booleanasc){if(buf==null){thrownewIllegalArgumentException("bytearrayisnull!");}if(buf.length>8){thrownewIllegalArgumentException("bytearraysize>8!");}longr=0;if(!asc)for(inti=buf.length-1;i>=0;i--){r<<=8;r|=(buf[i]&0x00000000000000ff);}elsefor(inti=0;i<buf.length;i++){r<<=8;r|=(buf[i]&0x00000000000000ff);}returnr;}}package com.unity.socket;public class ConvertType {public ConvertType(){} public final static byte[] getBytes(float s,boolean asc){ int buf=(int)(s*100); return getBytes(buf,asc); } public final static float getFloat(byte[] buf,boolean asc){ int i=getInt(buf,asc); float s=(float)i; return s/100; }public final static byte[] getBytes(short s, boolean asc){ byte[] buf = new byte[2]; if (asc) { for (int i = buf.length - 1; i >= 0; i--) { buf[i] = (byte) (s & 0x00ff); s >>= 8; } } else { for (int i = 0; i < buf.length; i++) { buf[i] = (byte) (s & 0x00ff); s >>= 8; } } return buf; } public final static byte[] getBytes(int s, boolean asc) { byte[] buf = new byte[4]; if (asc) for (int i = buf.length - 1; i >= 0; i--) { buf[i] = (byte) (s & 0x000000ff); s >>= 8; } else for (int i = 0; i < buf.length; i++) { buf[i] = (byte) (s & 0x000000ff); s >>= 8; } return buf; } public final static byte[] getBytes(long s, boolean asc) { byte[] buf = new byte[8]; if (asc) for (int i = buf.length - 1; i >= 0; i--) { buf[i] = (byte) (s & 0x00000000000000ff); s >>= 8; } else for (int i = 0; i < buf.length; i++) { buf[i] = (byte) (s & 0x00000000000000ff); s >>= 8; } return buf; } public final static short getShort(byte[] buf, boolean asc) { if (buf == null) { throw new IllegalArgumentException("byte array is null!"); } if (buf.length > 2) { throw new IllegalArgumentException("byte array size > 2 !"); } short r = 0; if (!asc) for (int i = buf.length - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0x00ff); } else for (int i = 0; i < buf.length; i++) { r <<= 8; r |= (buf[i] & 0x00ff); } return r; } public final static int getInt(byte[] buf, boolean asc) { if (buf == null) { throw new IllegalArgumentException("byte array is null!"); } if (buf.length > 4) { throw new IllegalArgumentException("byte array size > 4 !"); } int r = 0; if (!asc) for (int i = buf.length - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0x000000ff); } else for (int i = 0; i < buf.length; i++) { r <<= 8; r |= (buf[i] & 0x000000ff); } return r; } public final static long getLong(byte[] buf, boolean asc) { if (buf == null) { throw new IllegalArgumentException("byte array is null!"); } if (buf.length > 8) { throw new IllegalArgumentException("byte array size > 8 !"); } long r = 0; if (!asc) for (int i = buf.length - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0x00000000000000ff); } else for (int i = 0; i < buf.length; i++) { r <<= 8; r |= (buf[i] & 0x00000000000000ff); } return r; }}很简单的demo,有一定的可扩展性,需要工程的可以下载来看,下载链接http://download.csdn.net/detail/genius840215/4187126 如void WINAPI glGenTextures( GLsizei n, GLuint *textures);void WINAPI glBindTexture( GLenum target, GLuint texture);纹理在OpenGL库内部也是一个复杂的结构体,同样使用句柄的概念对外隐藏了实现细节 大发888娱乐场最垃圾的斗技了

【更多热点请手机下载《爱济南》客户端 山东大小事尽在掌握】

原标题:大发888网上投注凭你现在的实力
分享到:
值班主任:田艳敏
免责声明:凡本网注明“来源:XXX(非舜网)”的作品,均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。本网转载其他媒体之稿件,意在为公众提供免费服务。如稿件版权单位或个人不想在本网发布,可与本网联系,本网视情况可立即将其撤除。