Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Capture the screen into a bitmap, encode it as an image, then send the encoded bytes over TCP with a length prefix so the receiver knows exactly where the screenshot ends. The example below uses Graphics.CopyFromScreen on Windows and a four-byte big-endian length header; the receiver validates that length and reads the entire payload before saving it.
Keep capture, encoding, transport, and decoding or storage as separate steps. That makes it easier to change the image format or transport without entangling the code, and it gives the receiver a clear point to reject oversized or incomplete messages.
What the socket protocol needs to do
TCP delivers an ordered stream of bytes, not separate image messages. A call that writes one image does not guarantee that the peer will receive it in one matching read. Define a framing rule: this example sends a four-byte unsigned payload length in network byte order (big-endian), followed by exactly that many image bytes.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteThe receiver first reads all four header bytes, parses the length, checks it against a configured maximum, and then loops until it has all the announced payload bytes. A peer that disconnects early has sent an incomplete message; do not treat it as a valid image. This simple protocol handles one screenshot per connection. To send multiple screenshots on one connection, repeat the header-and-payload sequence and define how the receiver distinguishes orderly shutdown from another message.
#1 Best Overall
- 𝐇𝐢𝐠𝐡-𝐒𝐩𝐞𝐞𝐝 𝐔𝐒𝐁 𝐄𝐭𝐡𝐞𝐫𝐧𝐞𝐭 𝐀𝐝𝐚𝐩𝐭𝐞𝐫 - UE306 is a USB 3.0 Type-A to RJ45 Ethernet adapter that adds a reliable wired network port to your laptop, tablet, or Ultrabook. It delivers fast and stable 10/100/1000 Mbps wired connections to your computer or tablet via a router or network switch, making it ideal for file transfers, HD video streaming, online gaming, and video conferencing.
- 𝐔𝐒𝐁 𝟑.𝟎 𝐟𝐨𝐫 𝐅𝐚𝐬𝐭𝐞𝐫, 𝐌𝐨𝐫𝐞 𝐒𝐭𝐚𝐛𝐥𝐞 𝐃𝐚𝐭𝐚 𝐓𝐫𝐚𝐧𝐬𝐟𝐞𝐫𝐬- Powered via USB 3.0, this adapter provides high-speed Gigabit Ethernet without the need for external power(10/100/1000Mbps). Backward compatible with USB 2.0/1.1, it ensures reliable performance across a wide range of devices.
- 𝐒𝐮𝐩𝐩𝐨𝐫𝐭𝐬 𝐍𝐢𝐧𝐭𝐞𝐧𝐝𝐨 𝐒𝐰𝐢𝐭𝐜𝐡- Easily connect your Nintendo Switch to a wired network for faster downloads and a more stable online gaming experience compared to Wi-Fi.
- 𝐏𝐥𝐮𝐠 𝐚𝐧𝐝 𝐏𝐥𝐚𝐲- No driver required for Nintendo Switch, Windows 11/10/8.1/8, and Linux. Simply connect and enjoy instant wired internet access without complicated setup.
- 𝐁𝐫𝐨𝐚𝐝 𝐃𝐞𝐯𝐢𝐜𝐞 𝐂𝐨𝐦𝐩𝐚𝐭𝐢𝐛𝐢𝐥𝐢𝐭𝐲- Supports Nintendo Switch, PCs, laptops, Ultrabooks, tablets, and other USB-powered web devices; works with network equipment including modems, routers, and switches.
Capture and send a screenshot from Windows
Graphics.CopyFromScreen copies pixels from a selected screen rectangle into a drawing surface. The code below captures the primary display, encodes the bitmap as PNG in memory, and sends it to a receiver listening on port 5000. The capture API is Windows-specific; it is not a portable way to capture screens on macOS or Linux.
Create a Windows console project targeting Windows, for example dotnet new console -n ScreenshotSender -f net8.0-windows, and enable Windows Forms in the project file so the Windows desktop drawing APIs are available:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Replace Program.cs with the following. Set the receiver address to a machine reachable from the sender. The receiver example later in this article listens on all interfaces; restrict that exposure with your firewall and use TLS and authentication outside a trusted, controlled network.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Rank #2
- Connects a USB 3.0 device (computer/laptop) to a router, modem, or network switch to deliver Gigabit Ethernet to your network connection. Does not support Smart TV or gaming consoles (e.g.Nintendo Switch).
- Supported features include Wake-on-LAN function, Green Ethernet & IEEE 802.3az-2010 (Energy Efficient Ethernet)
- Supports IPv4/IPv6 pack Checksum Offload Engine (COE) to reduce Cental Processing Unit (CPU) loading
- Compatible with Windows 8.1 or higher, Mac OS
using System.Drawing;
using System.Drawing.Imaging;
using System.Net.Sockets;
using System.Buffers.Binary;
const string host = "127.0.0.1";
const int port = 5000;
// Capture the primary display. For a specific region, substitute its
// screen-coordinate origin and width/height here.
var bounds = System.Windows.Forms.Screen.PrimaryScreen?.Bounds
?? throw new InvalidOperationException("No primary display was found.");
byte[] imageBytes;
using (var bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen(bounds.Left, bounds.Top, 0, 0, bounds.Size);
}
using var imageStream = new MemoryStream();
bitmap.Save(imageStream, ImageFormat.Png);
imageBytes = imageStream.ToArray();
}
if (imageBytes.Length == 0)
throw new InvalidOperationException("The encoded screenshot is empty.");
using var client = new TcpClient();
await client.ConnectAsync(host, port);
await using NetworkStream stream = client.GetStream();
byte[] header = new byte[4];
BinaryPrimitives.WriteUInt32BigEndian(header, checked((uint)imageBytes.Length));
await stream.WriteAsync(header);
await stream.WriteAsync(imageBytes);
await stream.FlushAsync();
Console.WriteLine($"Sent {imageBytes.Length} bytes of PNG data to {host}:{port}.");
The bitmap and graphics objects are disposed as soon as capture and encoding finish. Image.Save(Stream, ImageFormat) writes the encoded image to a memory stream; ToArray() provides the bytes that are sent. PNG is a useful default for screenshots containing text and interface edges because it is lossless. JPEG can reduce payload size for photographic content, but it is lossy; choose based on the image and the acceptable trade-off, not an assumed universal winner.
Receive the framed image and save it
This cross-platform console receiver listens on port 5000, accepts one connection, reads the header and complete payload, then writes the bytes to received.png. It caps the accepted payload at 25 MiB; adjust that limit to the use case, but keep a deliberate bound rather than trusting a sender-provided length.
Create it with dotnet new console -n ScreenshotReceiver and replace Program.cs:
Rank #3
- COMPACT DESIGN - The compact-designed portable BENFEI USB A/C to Ethernet adapter connects your computer or tablet to a router,modem or network switch for network connection. It adds a standard RJ45 port to your Ultrabook, notebook or Macbook Air for file transferring, video conferencing, gaming, and HD video streaming.
- SUPERIOR STABILITY - Built-in advanced IC chip works as the bridge between RJ45 Ethernet cable and your USB A/C devices. The driver-free installation with native driver support in Chrome, Mac, and Windows OS; The USB A/C Ethernet adapter dongle supports important performance features including Wake-on-Lan (WoL), Full-Duplex (FDX) and Half-Duplex (HDX) Ethernet, Crossover Detection, Backpressure Routing, Auto-Correction (Auto MDIX).
- INCREDIBLE PERFORMANCE - Supports full 10/100/1000Mbps gigabit ethernet performance over USB A/C's 5Gbps bus, faster and more reliable than most wireless connections. Link and Activity LEDs. USB powered, no external power required. Backward compatible with USB 2.0/1.1.✅ To reach 1Gbps, make sure to use CAT6 & up Ethernet cables.
- BROAD COMPATIBILITY - The USB A/C-Ethernet adapter is compatible with Windows 11/10/8.1/8/7/Vista/XP, Mac OSX 10.6/10.7/10.8/10.9/10.10/10.11/10.12, Linux kernel 3.x/2.6, Android and Chrome OS.Compatible with IEEE 802.3, IEEE 802.3u and IEEE 802.3ab. Supports IEEE 802.3az (Energy Efficient Ethernet).❌Do Not Support Windows RT. (NOT compatible with Nintendo Switch.)
- 18 MONTH WARRANTY - Exclusive BENFEI Unconditional 18-month Warranty ensures long-time satisfaction of your purchase; Friendly and easy-to-reach customer service to solve your problems timely.
using System.Buffers.Binary;
using System.Net;
using System.Net.Sockets;
const int port = 5000;
const uint maxPayloadBytes = 25 * 1024 * 1024;
var listener = new TcpListener(IPAddress.Any, port);
listener.Start();
Console.WriteLine($"Listening on port {port}...");
try
{
using TcpClient client = await listener.AcceptTcpClientAsync();
await using NetworkStream stream = client.GetStream();
byte[] header = new byte[4];
await ReadExactlyAsync(stream, header);
uint payloadLength = BinaryPrimitives.ReadUInt32BigEndian(header);
if (payloadLength == 0 || payloadLength > maxPayloadBytes)
throw new InvalidDataException($"Rejected payload length: {payloadLength} bytes.");
byte[] imageBytes = new byte[checked((int)payloadLength)];
await ReadExactlyAsync(stream, imageBytes);
// This sample stores the received bytes. Validate/decode the image before
// using it in an application that treats senders as untrusted.
await File.WriteAllBytesAsync("received.png", imageBytes);
Console.WriteLine($"Saved {imageBytes.Length} bytes to received.png.");
}
catch (EndOfStreamException ex)
{
Console.Error.WriteLine($"Connection ended before a complete message arrived: {ex.Message}");
}
finally
{
listener.Stop();
}
static async Task ReadExactlyAsync(Stream stream, Memory<byte> buffer)
{
int totalRead = 0;
while (totalRead < buffer.Length)
{
int read = await stream.ReadAsync(buffer[totalRead..]);
if (read == 0)
throw new EndOfStreamException("The peer closed the connection.");
totalRead += read;
}
}
Run the receiver first, then run the sender. TcpClient.GetStream() returns the NetworkStream used to exchange data. The exact-read loop matters: a stream read may return fewer bytes than requested, including for the small header. The receiver’s one-client, one-message shape is suitable for demonstrating framing, not a complete multi-client service. A production listener should accept clients repeatedly, isolate each connection, apply timeouts or cancellation, and define how it reports failures.
Adapt the capture, format, and message envelope
Capture a region or another display
For a rectangle, create the bitmap with the rectangle’s width and height, then pass its screen-coordinate origin to CopyFromScreen. The destination origin is normally 0, 0 because the new bitmap starts at its own top-left corner. For a different monitor, select its bounds instead of PrimaryScreen.Bounds. Check that the selected display exists and that dimensions are positive before allocating a bitmap; very large dimensions can consume substantial memory.
Choose an image format
Use an explicit image format instead of relying on a filename extension. PNG retains sharp text and is broadly suitable for UI captures. JPEG is lossy and may be smaller for photographic material. The transmitted header in this example carries only the length, so both peers must agree on the image format. If peers may use different formats, add a small, versioned envelope containing a format identifier and validate it before handling the payload.
Rank #4
- Dual USB-A/C Port Design: This USB hub with ethernet adapter features dual connectors for both USB C and USB A devices, ensuring wide compatibility across laptops, tablets, and smartphones. It includes 1x Gigabit Ethernet port and 3x USB A 3.0 ports, all usable at the same time for smooth and efficient connectivity. 📌Note: When using USB-A to connect devices, please ensure the USB-C is securely attached to the USB-A connector.
- Stable Gigabit Ethernet Adapter: Get fast, wired Internet up to 1000Mbps with this USB C to ethernet adapter. Backward compatible with 10/100Mbps networks for flexible connectivity across various setups. Ideal for streaming, gaming, and large file transfers. 📌Note: Ensure the RJ45 connector is plugged in securely in the port and use CAT6 & above Ethernet cable is required to reach 1 Gbps.
- 5Gbps Data Transfer: Transfer large files, photos, and videos in seconds with this USB 3.0 hub supporting speeds up to 5Gbps—10× faster than USB 2.0. Backward compatible with USB 2.0 and 1.1 devices, this USB splitter expands one port into three for connecting keyboards, mice, and flash drives for everyday use. 📌Note: The three USB-A 3.0 ports share a total 5Gbps bandwidth.【NO HDMI port, NO USB-C data port, and NO PD charging】
- Plug and Play: Reliable USB to ethernet adapter ready to use in seconds. Instantly connects with USB-A and USB-C devices including MacBook Pro/Air, iPad Pro, iMac, Surface Laptops, Chromebook, XPS, tablets, Steam, and smartphones. Works with Windows, macOS, Linux, Chrome OS, and Android. 📌XP/Win7 may need driver. Older systems may not recognize this product due to its USB 3.0 chip. Please refer to the “Installation Manual” to manually download and install the driver.
- Durable & Portable Build: Made with sturdy aluminum alloy, this RJ45 to USB-C adapter delivers long-term durability, efficient heat dissipation, and stable performance for offices, corporate deployments, classrooms, and campus workstations—while its slim, portable form factor makes it ideal for business travel, educators, and mobile professionals.
Extend framing deliberately
A four-byte length prefix is enough for one bounded image per connection. If the application needs multiple messages per connection, add a protocol version, message type, request identifier, or timestamp as needed, and specify each field’s width and byte order. Validate metadata and lengths before allocating buffers. For sustained traffic or large captures, consider streaming a bounded payload to storage rather than allocating a second full-size array; the example favors clarity over minimizing copies.
Protect screenshots when the network is not trusted
Plain TCP does not encrypt screenshots or prove the identity of the peer. On a network beyond a controlled trusted boundary, wrap the network stream in SslStream, authenticate the server and, where appropriate, the client, and send the framed message only after authentication succeeds. TLS reads are not available until authentication completes. Use certificate validation rather than accepting any certificate, and retain application-level authorization, payload limits, and careful handling of screenshot data in memory and on disk. Encryption does not decide who is allowed to capture or view a screen.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Performance, reliability, and cost considerations
- Payload size: full-display captures create larger payloads than cropped regions. Capture only the area the receiver needs, and select PNG or JPEG based on fidelity requirements.
- Responsiveness: the examples use asynchronous network operations so a UI or service can avoid blocking while connecting and transferring. Capture and encoding still consume CPU and memory; run them off a UI thread in a desktop application.
- Connection failures: a refused connection usually means no listener is available at the target host and port; a timeout or unreachable host points to routing or firewall configuration. Retry only with a policy that prevents duplicate processing or uncontrolled retry loops.
- Partial or truncated data: the receiver must complete both reads and treat early closure as failure. Do not save or process an incomplete payload as if it were valid.
- Resource limits: validate the length before allocating, and consider limits on concurrent clients, capture dimensions, and total processing time. A valid but very large image can still exhaust memory.
The code performs no compression beyond the selected image encoding and makes no claim about throughput; actual transfer time depends on image content, capture dimensions, network conditions, and receiver work.
Best Value
- [Expansion Ports] The USB C to Ethernet Adapter expands the device to three USB 3.0 ports and one Gigabit Ethernet port. Provides you more peripheral ports while maintaining a stable network connection, plug and play, no driver required.
- [Gigabit Network Port] ALL-LUCKY USB Ethernet Adapter transmission rate up to 1000Mbps, also compatible with 10/100Mbps bandwidth. It allows you to enjoy a smooth and stable network connection and avoid too much lag. (Note: To reach 1Gbps, please use CAT6 or above Ethernet cable connection)
- [Convertible Connector]This usb hub with ethernet not only has USB-A connector, but also can be converted to USB-C connector, so that you can easily convert the connector according to the device port, improve the convenience of use.
- [High-Speed Data Transfer] The usb to ethernet adapter adopts USB 3.0 transmission technology, supports up to 5Gbps transmission rate, and is compatible with USB 2.0(480Gbps),USB 1.0(12Mbps), easily transfer video, files and other data for you in seconds. (Note: Maximum output current is 900mA, does not support charging devices.)
- [Widely Compatible]The usb c ethernet adapter for iMac, MacBook Pro, iPad Pro, XPS and many other devices. Compatible with Windows 11/10/8.1/8, Mac OS, iPad OS, Chrome OS.(Note: Driver is required on Win 7) It can be used in office, school, library and other occasions, compact and portable, easy to carry around.
Troubleshooting common failures
- “No primary display was found” or a capture exception: run in an interactive Windows desktop session with an available display. The shown API is not a headless cross-platform capture solution.
- Connection refused: start the receiver before the sender, confirm both use the same port and correct host, and check that local or network firewall rules allow the connection.
- Sender connects but receiver hangs: confirm both sides use the same framing: exactly four big-endian length bytes followed by that many payload bytes. A disagreement about byte order or message format can make the receiver wait for an implausible amount of data.
- Receiver rejects the length: ensure the header is not being sent as text or in little-endian order, and verify that the sender’s payload is within the receiver’s configured maximum.
- Received file will not open: confirm the sender encoded PNG and that the receiver received the entire payload. Do not use the filename extension as proof that the bytes are actually PNG.
- Works locally but not between machines: replace
127.0.0.1with the receiver machine’s reachable address, bind and firewall the listener appropriately, and verify network routing. Do not expose an unauthenticated screenshot receiver to an untrusted network.
Or skip the browser setup
If what you need is a screenshot of a web page rather than pixels from a local Windows desktop, ScreenshotNeo can return a webpage screenshot through one API request. It is a different workflow from sending a locally captured desktop image over your own socket: use the socket example when your application needs to capture and deliver its own screen data.
For API parameters and response details, see the ScreenshotNeo documentation. This cURL request saves a Stripe page capture as WebP:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots, and every feature is on every plan.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.
Frequently Asked Questions
Can I use the same length-prefix protocol for JPEG instead of PNG?
Yes. Encode as JPEG, keep the same framing, and make sure the receiver knows the agreed format or add a validated format identifier to the message.
Does the socket example capture a web page?
No. It captures pixels from a Windows display. For a webpage screenshot returned by an API rather than a local screen capture, ScreenshotNeo is a separate option.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Recommended Free Tools

