C# · .NET · Windows Forms · Networking

LAN-based Software for
Chat, Video Calling & File Transfer

A full-stack desktop communication platform built in C# .NET Windows Forms — enabling real-time text chat, video/audio calling, and file transfer over a Local Area Network without any internet dependency. Implemented with raw UDP sockets for peer-to-peer messaging, a custom Wave audio engine for voice transmission, a 3-tier architecture (GUI → Business Object Layer → SQL Server), and persistent chat history backed by SQL Server Express.

C# .NET Windows Forms UDP Sockets Wave Audio SQL Server LAN / P2P 3-Tier Architecture
Language
C# · .NET Framework
Platform
Windows Forms · Visual Studio
Networking
UDP Sockets · LAN · Peer-to-Peer
Database
SQL Server Express · local .mdf
Audio
Custom Wave Engine · winmm.dll P/Invoke
01About

This project is a Skype-like desktop communication suite that operates entirely over a Local Area Network — no internet, no third-party server, no cloud dependency. Any two machines on the same LAN can communicate directly by exchanging IP addresses and port numbers, making it ideal for closed networks such as university labs, offices, or corporate intranets.

The application was developed to explore low-level socket programming in C# — specifically how to build real-time bidirectional communication using raw UDP datagrams, handle asynchronous callbacks for non-blocking message receipt, and manage application state across multiple Windows Forms screens.

The software covers all three core communication modes: text chat via UDP with persistent history stored in SQL Server, voice/audio calls using a fully custom Wave audio engine that wraps Windows multimedia APIs via P/Invoke (no external libraries), and file transfer over the same LAN infrastructure. User accounts (login, signup) are managed with a dedicated Business Object layer separating data access from the UI.

The architecture follows a clean 3-tier pattern: the GUI layer (Windows Forms) talks exclusively to the BOLayer (a dedicated C# class library) which in turn manages all SQL Server interactions — a design pattern that was also applied in enterprise EDI systems later in the career at Spring Systems.

02Architecture

The application is structured as a 3-tier Windows application with a separate Visual Studio solution project for each layer. The GUI layer handles all Windows Forms events; the Business Object Layer (compiled as a separate DLL) isolates all SQL Server operations; and the database tier uses a local SQL Server Express .mdf file that can optionally be shared across a LAN via a database server for multi-user persistence.

Tier 1 — Presentation
GUI Layer
  • LogInGUI.cs
  • SignUpGUI.cs
  • SkypeGUI.cs (contacts)
  • ChatGUI.cs (messaging)
  • Windows Forms · .resx resources
SQL calls
via BOClass
Tier 2 — Business Logic
BOLayer.dll
  • BOClass.cs
  • chatHistorySave()
  • chatHistoryDisplay()
  • deleteChatHistory()
  • openConnection() / closeConnection()
SqlConnection
string
Tier 3 — Data
SQL Server Express
  • data.mdf (local / LAN)
  • tblChatHistory table
  • chat VARCHAR(50) column
  • INSERT · SELECT · DELETE
  • Integrated Security
Client A
192.168.x.x:PORT_A
←UDP→
1500-byte
datagrams
LAN Switch
UDP / IPv4
←UDP→
async
callback
Client B
192.168.x.x:PORT_B
03Features

Three communication modes are integrated into a single desktop application, all operating over the local network. Text chat uses the same UDP socket infrastructure as voice, keeping the implementation consistent across features. User state (login, contacts, history) is managed via SQL Server, making the application stateful even across sessions.

💬
Feature 01
Real-time Text Chat

UDP-based peer-to-peer messaging with 1,500-byte datagrams. Messages are sent via Socket.Send() and received asynchronously through BeginReceiveFrom() callbacks — keeping the UI thread unblocked. Displays sent/received messages separately. Enter key shortcut supported alongside the Send button.

UDP · Async · SQL history
🎙️
Feature 02
Voice / Audio Calling

Custom Wave audio engine built from scratch — no NAudio or external libraries. WaveIn.cs and WaveOut.cs wrap Windows Multimedia API (winmm.dll) via P/Invoke with native structs: WAVEFORMATEX, WAVEHDR, and WAVEOUTCAPS. Audio is captured, buffered, and transmitted over UDP to the remote peer.

winmm.dll · P/Invoke · PCM
📂
Feature 03
File Transfer

Peer-to-peer file transfer over the LAN using the same socket infrastructure. Files are read, serialised into byte buffers, and sent to the remote IP:port over the local network — no external protocol or cloud upload required. Suitable for documents, images, and other binary payloads within the same subnet.

Binary · Byte Buffer · LAN
👤
Feature 04
User Accounts & History

Full user account lifecycle — Login (LogInGUI), Sign Up (SignUpGUI), and persistent contact/chat history via SQL Server Express. Chat history is loaded from tblChatHistory on startup, saved per message, and can be fully cleared via a confirmation dialog. User profile pictures displayed via PictureBox with custom icon resources.

SQL Server · CRUD · Sessions
04Implementation

Two of the most technically involved components are the UDP socket layer and the custom Wave audio engine. Both are implemented without third-party libraries — relying on .NET's System.Net.Sockets for networking and direct Windows API P/Invoke for audio device management.

ChatGUI.cs — UDP Socket Setup
// On form load — bind local endpoint sck = new Socket( AddressFamily.InterNetwork, SocketType.Dgram, // UDP ProtocolType.Udp); sck.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); // Bind to local IP:port epLocal = new IPEndPoint( IPAddress.Parse(textLocalIp.Text), Convert.ToInt32(textLocalPort.Text)); sck.Bind(epLocal); // Connect to remote peer epRemote = new IPEndPoint( IPAddress.Parse(textRemoteIp.Text), Convert.ToInt32(textRemotePort.Text)); sck.Connect(epRemote); // Start async receive loop buffer = new byte[1500]; sck.BeginReceiveFrom( buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
UDP Peer-to-Peer Socket
System.Net.Sockets · AddressFamily.InterNetwork

A single UDP Socket is created at form load, bound to the local machine's LAN IP and a chosen port, then connected to the remote peer's IP and port. SocketOptionName.ReuseAddress allows the port to be reused if the application restarts.

Async Receive Callback
BeginReceiveFrom · IAsyncResult · non-blocking

BeginReceiveFrom with an AsyncCallback keeps the UI thread fully responsive while waiting for incoming messages. When a datagram arrives, MessageCallBack() decodes the 1,500-byte buffer using ASCIIEncoding, appends the message to the ListView, and immediately re-arms the receive loop.

LAN IP Auto-Detection
Dns.GetHostEntry · AddressFamily.InterNetwork

GetLocalIp() iterates the host's address list and returns the first IPv4 address — automatically populating the local IP field so users only need to enter the remote peer's IP, not their own.

Wave Audio — Native winmm.dll P/Invoke
// WAVEFORMATEX struct (native interop) [StructLayout(LayoutKind.Sequential)] public struct WAVEFORMATEX { public ushort wFormatTag; // PCM=1 public ushort nChannels; // 1=mono public uint nSamplesPerSec; // 44100 public uint nAvgBytesPerSec; public ushort nBlockAlign; public ushort wBitsPerSample; // 16-bit public ushort cbSize; } // P/Invoke to Windows Multimedia API [DllImport("winmm.dll")] public static extern MMSYSERR waveInOpen(ref IntPtr phwi, uint uDeviceID, ref WAVEFORMATEX pwfx, IntPtr dwCallback, IntPtr dwInstance, WavConstants dwFlags); // WavInDevice / WavOutDevice wrapper WavInDevice capture = new WavInDevice(); WavOutDevice playback = new WavOutDevice();
Custom Wave Audio Engine
winmm.dll · P/Invoke · No external libraries

The audio subsystem wraps the Windows Multimedia API directly through Platform Invocation Services (P/Invoke). All native structs — WAVEFORMATEX, WAVEHDR, WAVEOUTCAPS — are declared in C# with [StructLayout(LayoutKind.Sequential)] to match the exact memory layout expected by the Win32 API.

WaveIn / WaveOut Devices
WavInDevice.cs · WavOutDevice.cs · PCM capture

WaveIn.cs (16,759 bytes) manages microphone capture: opening the input device, setting up double-buffering with WAVEHDR headers, and streaming PCM audio frames into a buffer. WaveOut.cs handles playback — writing buffered audio back to the speaker output device on the receiving peer.

Error Handling
MMSYSERR enumeration · 30+ error codes

MMSYSERR.cs defines the full Windows Multimedia error code enumeration (MMSYSERR_NOERROR, MMSYSERR_BADDEVICEID, MMSYSERR_NOTENABLED, etc.) used to validate every API call return value — providing meaningful diagnostics for audio device failures.

05Screens
Screen 01
Login
LogInGUI.cs

Entry point of the application. User enters credentials and clicks "Keep Log In" to proceed to the main contacts screen. On success, instantiates SkypeGUI, shows it, and hides the login window — maintaining a single active window at any time.

Screen 02
Sign Up
SignUpGUI.cs

New user registration screen. Collects user details and persists them to the SQL Server database via the BOLayer. Linked from the Login screen via a "Register" or "Sign Up" route — keeping authentication flow self-contained.

Screen 03
Contacts / Home
SkypeGUI.cs

Main hub displaying the contact list in a ListView with dynamically generated contact buttons. Navigates to ChatGUI on contact selection. Contains the application's primary navigation logic and serves as the shell for all sub-features.

Screen 04
Chat Window
ChatGUI.cs

The core communication screen: dark-themed (charcoal gray panels, black input area) with a friend's profile picture and name in orange. Message history displayed in a scrollable RichTextBox; incoming messages in a ListView. Local/remote IP and port fields configure the UDP connection. "Delete History" button with confirmation dialog.

06Contributions
LanguageC# · .NET Framework
UI FrameworkWindows Forms · Visual Studio Designer · .resx resources
NetworkingSystem.Net.Sockets · UDP (SocketType.Dgram) · BeginReceiveFrom
AudioCustom Wave Engine · winmm.dll · P/Invoke · WAVEFORMATEX · WAVEHDR
DatabaseSQL Server Express · SqlConnection · SqlCommand · local .mdf
Architecture3-Tier · GUI Layer + BOLayer.dll + SQL Server
IDEVisual Studio · Eclipse CDT (audio prototype)
EncodingASCIIEncoding · byte[1500] datagram buffer

View the source code

Full C# solution including GUI, BOLayer, Wave audio engine, and SQL database on GitHub.