- 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
Project
menu - Select the
Properties
(by defaultAlt+F7
) - In opened window in left menu select
Linker
- In submenu select
Input
- In main view select
Additional Dependencies
andEdit...
- In opened subwindow in input print
ws2_32.lib
and clickOK
- Click
Apply
and thenOK
- Done!
-
Connect
Client
withServer
-
Add args for cli (Command line)
-
Client
can send message with size more thanbufferSize
-
Client
can send more than one message -
Server
can respond onClient
's message -
Server
can accept and listen more than oneClient
-
Server
can receive message from oneClient
and MAYBE send this message to othersClient
s
- Change splitting: vector -> char* (for optimize)
- Add maximum count of
Client
s - Every
Client
must have unique username - Add command
/exit
to 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.