09 2013 档案
摘要:基本没有问题,传输效率很高,缺点如博主所说,cpu占用问题,估计是浪费在指令、校验和判断上了,如果接收到我的文件用异步写入,应该也会减少点cpu时间。另外,博主可以尝试一下用md5校验,虽然有16字节,但是比crc32的效率快很多,cpu占用也少,在我的机器上实测,crc32,校验一个byte[],4兆字节用时7毫秒,400兆字节用时190多毫秒,而md5校验同样的字节数,分别用0毫秒和60多毫秒。0毫秒就是还没到1毫秒就完成了呵呵。我计时的方法是在computeHash之前timer.start(),之后stop,应该算精确的。期待与各位精通socket的朋友交流,goodies.qq@gm
阅读全文
摘要:ASCII方式:一个英文字母占一个字节,不能保存汉字;UTF8方式:一个英文字母占一个字节,一个汉字占三个字节;unicode方式:一个英文字母和一个汉字都占两个字节。基于TCP的Socket服务端:1、客户端以UTF8编码发送数据,假如发送的数据是汉字的情况下 服务端进行接收的时候,接收的缓冲区的长度必须至少大于等于3个字节。 byte[] buffer = new byte[length] // length的长度>=32、客户端以unicode编码发送数据,假如发送的数据是汉字的情况下 服务端进行接收的时候,接收的缓冲区的长度必须至少大于等于2个字节 byte[] bu...
阅读全文
摘要:ConclusionAnd that's all there is to it! Here is how our client looks likeHere is how our server looks likeThat is all there is to the socket programming.
阅读全文
摘要:Server SideIf you have understood whatever I have described so far, you will easily understand the Server part of the socket application. So far we have been talking about a client making connection to a server and sending and receiving data.On the Server end, the application has to send and receive
阅读全文
摘要:Now lets say you have two sockets connecting to either two different servers or same server (which is perfectly valid) . One way is to create two different delegates and attach a different delegate to different BeginReceive function. What if you have 3 sockets or for that matter n sockets , this app
阅读全文
摘要:Getting StartedYou can argue that one can overcome these shortcomings by multithreading meaning that one can spawn a new thread and let that thread do the polling which then notifies the main thread of the data. This concept could work well, but even if you create a new thread it would require your
阅读全文
摘要:This is the second part of the previous article about the socket programming. In the earlier article we created a client but that client used to make blocking IO calls ( Receive ) to read data at regular intervals (via clicking the Rx button). But as I said in my earlier article, that model does not
阅读全文
浙公网安备 33010602011771号