- Initialize WSA -
WSAStartup() - Create a socket -
socket() - Bind the socket -
bind() - Listen on the socket -
listen() - Accept a connection -
accept()/connect() - Send and receive data -
recv(),recvfrom/send(),sendto() - Disconnect -
closesocket()
Before you develop Windows Sockets programs within Visual Studio, you must include the ws2_32.lib library within your Project.
Create a new C++ Console Project and follow the steps belows:
- Select the
Projectmenu - Select the
Properties(by defaultAlt+F7) - In opened window in left menu select
Linker - In submenu select
Input - In main view select
Additional DependenciesandEdit... - In opened subwindow in input print
ws2_32.liband clickOK - Click
Applyand thenOK - Done!
-
Connect
ClientwithServer -
Add args for cli (Command line)
-
Clientcan send message with size more thanbufferSize -
Clientcan send more than one message -
Servercan respond onClient's message -
Servercan accept and listen more than oneClient -
Servercan receive message from oneClientand MAYBE send this message to othersClients
- Change splitting: vector -> char* (for optimize)
- Add maximum count of
Clients - Every
Clientmust have unique username - Add command
/exitto leave chat - Add command
/private [username]to send private message - Add formatted output (BETA)
IP ADDRESS: 127.0.0.1
PORT: 55555
The Winsock dll found!
The status: Running
socket() is OK!
bind() is OK!
Start listening on port: 55555
Accepted connection 1/10
Accepted connection 2/10
[2023-11-08 22:10:19] user2: hi, user1
[2023-11-08 22:10:32] user1: hello, user2
[2023-11-08 22:10:50] user1: how are u?
Client has terminated the connection
Client's socket was closed 1/10
Client has terminated the connection
Client's socket was closed 0/10
IP ADDRESS: 127.0.0.1
PORT: 55555
The Winsock dll found!
The status: Running
socket() is OK!
Client connect() is OK!
Enter your username (5-20 symbols): user1
[2023-11-08 22:10:19] user2: hi, user1
[2023-11-08 22:10:32] user1: hello, user2
[2023-11-08 22:10:50] user1: how are u?
...
user1 (YOU) > /exit
Client closed the connection.
IP ADDRESS: 127.0.0.1
PORT: 55555
The Winsock dll found!
The status: Running
socket() is OK!
Client connect() is OK!
Enter your username (5-20 symbols): user2
[2023-11-08 22:10:19] user2: hi, user1
[2023-11-08 22:10:32] user1: hello, user2
[2023-11-08 22:10:50] user1: how are u?
...
user1 (YOU) > /exit
Client closed the connection.