.NET Framework Bookmark and Share   
 index > Network Class Library (System.Net) > About the Socket.SendPacketsAsync() method...
 

About the Socket.SendPacketsAsync() method...

As title.
If a client send a file via this method,
how do I get the file with Socket.ReceiveAsync() (or other) method on my server application?
I guess the answer is about the SocketAsyncEventArgs class, but I don't know how to do...



Thank you:)
Reassert
it doesnt matter how a client sends the data, the server can recieve it however u specify
UQUE
Thank you for your reply :)
So according toyour reply,the answer is SocketAsyncEventArgs.Buffer property,samethingthat I receive a text message from client, I think.
I'm going totry it :)

I had this question because the page of SocketAsyncEventArgs.Buffer on MSDN:

http://msdn.microsoft.com/en-us/library/system.net.sockets.socketasynceventargs.buffer.aspx

As you can see, the Remark section in this page:

"This property is used with the Socket.AcceptAsync, Socket.ConnectAsync, Socket.ReceiveAsync, Socket.ReceiveFromAsync, Socket.ReceiveMessageFromAsync, Socket.SendAsync, and Socket.SendToAsync methods."

There's no Socket.SendPacketsAsync() method in this section :)
By the way, how do I ascertain the data in SocketAsyncEventArgs.Buffer is a file(for example: bitmap) or text message?
Thanks again :)

Reassert
I'm not into Asynchronous communication, it is harder than synchronous one ;)

If you would change your mind :) check my solution here..

http://www.codeproject.com/KB/IP/2WRCS.aspx

Also, it has got an answer for your question about message type. You define it your self with flag bytes.


M.K.
Khallaf

As UQUE says, a Socket is simply used for moving bytes from place to place. What those bytes mean (file, text message, random gibberish), is completely up to you, the application developer, to decide.

SendPacketsAsync allows you to send bytes by passing in a combination of byte[] (which will be sent across verbatim) and filenames (the files will be opened and the contents will be sent across). On the receiving side, this still shows up as a stream of bytes, exactly as if you had sent it using SendAsync. To receive it, you callReceiveAsync - the Buffer of the SocketAsyncEventArgs you pass will be filled with some bytes from the stream.

It's up you to determine what those bytes mean in the context of your application. If you're expecting the client to send a file, you may want to write them to a FileStream. If you're expecting atext message, you'll handle them differently. An easy way of figuring this out is by sending a smallcontrol message before each chunk of data, saying in essence "I'm about to send you 12343 bytes, and it's a file." The server then knows what to expect, and can handle it appropriately.

Hope this helps,
-dave

Dave Murray [NCL]

You can use google to search for other answers

Custom Search

More Threads

• SSL wiht TcpClient
• check facebook user online status (C#)?
• Extraction of a web page content
• WebClient FTP download with credentials
• WebRequest.DownloadFile behind proxy
• Can't detect TcpListener remote connection closed
• (C#) Failed to get data from httpserver using tcp
• HttpWebRequest WebHeaders & Properties
• WebRequestMethods.Ftp.ListDirectory doesn't list all files..
• HTTP protocol errors when combining WebClient uploads and digest authentication