本文介绍了.NET新手插座问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我用写了一个C#客户端/服务器网络程序的TCPListener和的TcpClient类。服务器读取一切从客户端(少量的XML)就好了,直到我尝试发送大文件(100K)返回给客户端。

I have a C# client/server network program I've written usingTCPListener and TCPClient classes. The server is reading everythingfrom the client (small amounts of xml) just fine until I try to send alarge file (100k) back to the client.

我使用的是流功能客户端和服务器与非阻塞socket函数。当我做了socket.SendFile(文件名)返回给客户端,文件是变切断了 - 我已经设置的接收缓冲区大小的客户端来早已过上10万,但它仍然被切断周围25K和通信客户端和服务器之间是不可靠的后记。

I'm using stream functions forboth client and server with non-blocking socket functions. When I do asocket.SendFile("filename") back to the client, the file is gettingcut off - I've set the receive buffer size on the client to well past100k but it still gets cut off around 25k and the communicationbetween client and server is unreliable afterwords.

我的基本问题是,如果数据以某种方式留在管道中会发生什么?即..会是在接下来的socket.Read读...是否每次发送调用需要完全有且仅有一个读?也许我不会给客户足够的时间来读,但他们无论是在同一台机器上的文件,我已经试过睡在不同的地方W / O型成功的几秒钟。

My basic questionis what happens if data is somehow left in the pipe ? i.e.. will it beread by the next socket.Read... Does every Send call require exactlyone and only one Read ? Maybe I'm not giving the client enough time toread the file but their both on the same machine and I've triedsleeping for a few seconds in various places w/o success.

推荐答案

1发送调用可能需要一个以上的读取调用接收和1读取调用可能会读出的数据发送给几个发送呼叫。

1 Send call might take more than one Read call to receive, and 1 Read call might read the data send by several Send call.

TCP只是提供了一个数据流,所以它是由你来定义你发送的数据或信息是如何被分割。

TCP just provides a stream, so it's up to you to define how the data or messages you send are partitioned.

在这种情况下,你可能只需要循环,做阅读,直到流被关闭。

In this case, you probably just need to loop ,doing Read until the stream is closed.

这篇关于.NET新手插座问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:06
查看更多