Simple server client chat bot written in C++ adapted from workshop by ACM IIT Roorkee Student Chapter.
It creates a connection to the server and can send and recieve text messages.
- C++
- Socket Programming
- Clone the repo.
- Use either the TCP or UDP choose relevant directory.
- Open terminal and compile the files server.cpp and client.cpp
g++ server.cpp -o server
g++ client.cpp -o client
- Start the server on a specified port.
./server PORT
- In another terminal window connect the client to server.
./client localhost PORT
NOTE: If you compile it on a windows machine, it might throw an error:
server.cpp:2:10: fatal error: sys/socket.h: No such file or directory
2 | #include <sys/socket.h>
| ^~~~~~~~~~~~~~
compilation terminated.
This happens as:
<sys/socket.h> is for UNIX/Linux.
For windows, you use <Winsock2.h>. You'll also need to link against Ws2_32.lib and call WSAStartup to use WinSock.