![]() |
|
[C#] Pictures Not Sending Fully Over TCP - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] Pictures Not Sending Fully Over TCP (/showthread.php?tid=5534385) |
Pictures Not Sending Fully Over TCP - true - Jan 26, 2017 I have a server & client model. The client is supposed to take a screenshot, and then send it to the server. The problem I'm having, is part of the screenshot is missing. What I mean by this is like 3/4 of the screen is black when opened in Paint or another app. When I send the screenshot command a second time, the file doesn't open at all, it's corrupt. Here is my client side Code if (plainText.Contains("screenshot"))Here is my server side Code foreach (user c in clientList)I cannot seem to figure out what is causing the aforementioned issues in this code. * - zeroexp - Jan 26, 2017 Don't have time to test but try to debug and check if writebuffer.Length in the client is equal to the readBuffer.Length on the server. * - Zilog80 - Jan 26, 2017 Imagine the bitmap has 100000 Bytes. The problem is that in your client, you are assuming that you received 100000 bytes from the server, and you're putting all 100000 bytes into the memory stream. There is a great sample on the MSDN page for TcpClient which shows receiving from a TcpClient by using the underlying NetworkStream. Also, you will want to keep track of how many bytes you actually received (this is the return value from the NetworkStream.Read function). Finally, you'll want to keep reading until there is no more data to be read from the host. If your image is larger than your buffer, then you'll only have a partial image also. The sample on the linked page for NetworkStream.Read shows continually reading from the stream while there is data available. Source: http://stackoverflow.com/questions/6811760/sending-and-receiving-an-image-file-c-sharp TL;DR: what @Wops said * - Zilog80 - Jan 26, 2017 (Jan 26, 2017 03:00 PM)Submerged™ Wrote: So what you're saying is that my problem lies on the receiving end, not in the sender? In your 'server' (where you are 'receiving' the bitmap), put a breakpoint in this line: PHP Code Launch your client and 'send' a bitmap. Your server will be stop at the breakpoint and check the value for the readBuffer lenght. You will see that the 'length' you received is < than bytes lenght your client send. Hope it helps. Quote:Hm, I just checked. The buffer lengths are different. One of them is set to 65536, which is one more than the max amount of bytes in a packet. Check the links to MSDN from the SO thread I posted above and you will fix it 👍 * - Zilog80 - Jan 26, 2017 No idea how your code works, but maybe this would help: GrimEdittion TCP Library Framework: https://hackforums.net/showthread.php?tid=5527262 BahNahNah SyncIO: https://hackforums.net/showthread.php?tid=5506453 * - BahNahNah - Jan 26, 2017 Its most likely because its breaking up your packet. If you want to receive a single packet, use UDP (but look up the differences between the TCP/UDP because it probably dosent fit what you want to do) Its because TCP is a stream protocol, so the data comes trough like water in a pipe (If the pipe is a bit dodgy, you are not going to get all the water you want as fast as a new pipe). Where as UDP is like sending a postage box. Here is my approach of receving full packets through TCP even if they are (bigger than the buffer) https://github.com/BahNahNah/SyncIO/blob/master/SyncIO/Transport/PacketDefragmenter.cs Here are the tests too: https://github.com/BahNahNah/SyncIO/blob/master/SyncIOTests/Transport/PacketDefragmenterTests.cs * - Ninja - Jan 26, 2017 (Jan 26, 2017 06:25 PM)BahNahNah Wrote: Its most likely because its breaking up your packet. https://github.com/BahNahNah/SyncIO/blob/master/SyncIOTests/Transport/PacketDefragmenterTests.cs#L23 This one typo is bugging me more than it should. |