确定从套接字服务器发送的数据大小 [英] Determining the size of data being sent from Socket Server

查看:52
本文介绍了确定从套接字服务器发送的数据大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个Silverlight应用程序,它使用套接字来接收从套接字服务器推送到它的数据。 (Silverlight仅支持TCP协议)


套接字服务器将一系列图像推送到显示它们的Silverlight应用程序。每2秒钟,系列中的下一个图像被发送,直到所有图像都被发送,此时套接字服务器才重新开始。


一切正常工作正常现在,但这只是因为我已经使SocketAsyncEventArgs的接收缓冲区大小足以接受整个图像文件。


当接收缓冲区大小小于文件时,从服务器向客户端发送多个数据包,直到整个文件被发送为止。


我的问题是:我如何知道文件被发送的大小?



感谢您的时间,

-Frinny

解决方案

你控制文件发送吗?先发送数据?


谢谢Plater,


是的我控制双方。


我我也想到了这个解决方案,但似乎还有另一种方法可以做到这一点....


BeginSend 方法甚至采用一个参数来指示其大小正在发送的数据。


为什么我看不到这个客户端的价值?


我实际上是在考虑序列化每个数据包以便大小如此包含在开头....我上周正在阅读一篇文章,但是当我今天早上尝试访问它时,它已经没有了.....


也许这个序列化的东西不是最好的主意吗?


-Frinny


好msdn.com和我的本地msdn库似乎都是在查找SocketAsyncEventArgs对象时会发生故障。

如果你有权访问套接字,你可以看到当前流上有多少数据,这可能有点帮助?​​

我通常避免使用ASync这些非常分组的东西。的原因。

I''m implementing a Silverlight application that uses Sockets to receive data that is pushed to it from a Socket Server. (Silverlight only supports the TCP protocol)

The Socket Server pushes a series of images to the Silverlight application which displays them. Every 2 seconds the next image in the series is sent until all of the images have been sent, at which time the Socket Server just starts over again.

Everything''s working fine right now but that''s only because I''ve made the receive buffer size for the SocketAsyncEventArgs large enough to accept the whole image file.

When the receive buffer size is smaller than the file more than one packet is sent from the server to the client until the whole file''s been sent.

My question is: how do I know how large the file is that''s being sent?


Thanks for your time,

-Frinny

解决方案

Do you control the file sending? Send a datasize first?


Thanks Plater,

Yes I control both sides.

I have thought of that solution too but it seems that there should be another way to do this....

The BeginSend method even takes a parameter that indicates the size of the data being sent.

Why can''t I see this value client side?

I was actually thinking about serializing each packet so that the size would be included at the beginning....I was reading an article on this last week but when I tried access it this morning it wasn''t there any more.....

Maybe this serialization thing isn''t the best idea?

-Frinny


Well msdn.com and my local msdn library both seem to be broken when it comes to looking up that SocketAsyncEventArgs object.
If you have access to the socket, you can see how much data is currently on the stream though, that might help a bit?
I generally avoid using ASync stuff for these very "grouping" reasons.


这篇关于确定从套接字服务器发送的数据大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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