随笔分类 -  Socket

.net Socket
摘要:Socket提供了众多的属性,还提供了SetSocketOption方法来设置各种选项,对.NET网络应用程序的数据通讯进行“微调”。 Socket的功能出奇地强大,在.NET平台上,它支持以下四种典型的编程模式:(1) 居于阻塞模式的Socket编程(单线程或多线程的),每个线程处理一个客户端连接(2)“非阻塞”模式的Socket编程,这是早期UNIX为提升网络应用程序性能而采用的编程模式,出于兼容和方便移植原有程序的目的而保留,建议新开发的.NET网络程序不要再使用。(3) 使用IAsyncResult的异步编程模式:Socket类提供有一堆的“BeginXXX/EndXXX”方法实现.. 阅读全文
posted @ 2013-11-07 17:03 朱煜 阅读(410) 评论(0) 推荐(0)
摘要:基本没有问题,传输效率很高,缺点如博主所说,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 阅读全文
posted @ 2013-09-16 14:55 朱煜 阅读(6166) 评论(1) 推荐(0)
摘要:ASCII方式:一个英文字母占一个字节,不能保存汉字;UTF8方式:一个英文字母占一个字节,一个汉字占三个字节;unicode方式:一个英文字母和一个汉字都占两个字节。基于TCP的Socket服务端:1、客户端以UTF8编码发送数据,假如发送的数据是汉字的情况下 服务端进行接收的时候,接收的缓冲区的长度必须至少大于等于3个字节。 byte[] buffer = new byte[length] // length的长度>=32、客户端以unicode编码发送数据,假如发送的数据是汉字的情况下 服务端进行接收的时候,接收的缓冲区的长度必须至少大于等于2个字节 byte[] bu... 阅读全文
posted @ 2013-09-11 16:57 朱煜 阅读(971) 评论(0) 推荐(0)
摘要: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. 阅读全文
posted @ 2013-09-10 17:46 朱煜 阅读(250) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2013-09-10 17:45 朱煜 阅读(339) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2013-09-10 17:44 朱煜 阅读(357) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2013-09-10 17:42 朱煜 阅读(337) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2013-09-10 17:41 朱煜 阅读(289) 评论(0) 推荐(0)
摘要:假设接受文件的网页程序位于http://192.168.29.65/upload_file/UploadFile.假设我们要发送一个图片文件,文件名为“kn.jpg”, 首先客户端链接 192.168.24.56 后, 应该发送如下http 请求: POST/logsys/home/uploadIspeedLog!doDefault.htmlHTTP/1.1 Accept: text/plain, */* Accept-Language: zh-cn Host: 192.168.24.56 Content-Type:multipart/form-data;boundary=----... 阅读全文
posted @ 2012-11-07 16:39 朱煜 阅读(58666) 评论(0) 推荐(4)
摘要:一 原理区别 一般在浏览器中输入网址访问资源都是通过GET方式;在FORM提交中,可以通过Method指定提交方式为GET或者POST,默认为GET提交 Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP中的GET,POST,PUT,DELETE就对应着对这个资源的查 ,改 ,增 ,删 4个操作。到这里,大家应该有个大概的了解了,GET一般用于获取/查询 资源信息,而POST一般用于更新 资源信息(个人认为这是GET和POST的本质区别,也是协. 阅读全文
posted @ 2012-11-07 16:13 朱煜 阅读(944) 评论(0) 推荐(0)