.NET新手插座问题 [英] .NET newbie socket problem

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

问题描述

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

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

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

I'm using stream functions for both client and server with non-blocking socket functions. When I do a socket.SendFile("filename") back to the client, the file is getting cut off - I've set the receive buffer size on the client to well past 100k but it still gets cut off around 25k and the communication between client and server is unreliable afterwords.

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

My basic question is what happens if data is somehow left in the pipe ? i.e.. will it be read by the next socket.Read... Does every Send call require exactly one and only one Read ? Maybe I'm not giving the client enough time to read the file but their both on the same machine and I've tried sleeping 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新手插座问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆