https://github.com/dscmatter/winsockcomm
Demonstrates a basic TCP client-server communication setup using the Winsock API on Windows.
https://github.com/dscmatter/winsockcomm
cpp network-programming network-security networking windows winsock2
Last synced: about 2 months ago
JSON representation
Demonstrates a basic TCP client-server communication setup using the Winsock API on Windows.
- Host: GitHub
- URL: https://github.com/dscmatter/winsockcomm
- Owner: DSCmatter
- License: mit
- Created: 2025-06-05T01:54:20.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-05T07:11:53.000Z (about 1 year ago)
- Last Synced: 2025-06-16T19:53:48.610Z (about 1 year ago)
- Topics: cpp, network-programming, network-security, networking, windows, winsock2
- Language: C++
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WinsockComm
Demonstrates a basic TCP client-server communication setup using the Winsock API on Windows. It includes functionality for secure port binding using `SO_EXCLUSIVEADDRUSE`.
## Features
* TCP client and server using Winsock2
* Secure port binding with `SO_EXCLUSIVEADDRUSE`
* Simple echo server: sends back received messages
## Files
* `server.cpp`: Sets up a TCP server that listens on a specified port, accepts client connections, and echoes back received messages.
* `client.cpp`: Connects to the server, sends a message, and prints the response.
## How to Build
### Prerequisites
* Windows OS (Done on Windows 11 64-bit)
* MinGW for compilation
### Compile:
```sh
g++ server.cpp -o server.exe -lws2_32
g++ client.cpp -o client.exe -lws2_32
```
## How to Run
### Run Server
```bash
\.server.exe
```
This starts the server and begins listening for incoming connections on port 27015.
### Run Client
```bash
\.client.exe localhost
```
This connects to the server running on localhost and sends a test message.
### Input: "hello" // from client.cpp
### Output:
```
Bytes Sent: 5
Bytes received: 5
Connection closed
```
## Security
### Port Binding
The server uses the `SO_EXCLUSIVEADDRUSE` socket option to prevent other applications from binding to the same port while the server is running.
### Communication
Currently, the communication is done over plain TCP.
## License
This project is for educational purposes and is licensed under the MIT License.