RUVIDEO
Поделитесь видео 🙏

TCP client server application

In this video, we will be creating a TCP client-server application in Ubuntu Linux.

Try to make two separate .cpp files one of server_tcp and the other of client_tcp as shown in the video ;
then open two terminal windows. using the command "cd "and "ls" to reach the files one in each terminal window.
in the server terminal window use the command of "su" to change the $ sign to #
if you confront any error use the command "sudo passwd root" and change the password this time you run the command "su" which will not give any error, to close it use the command "exit".
The code is given below without less than less than sign!!! In order to Copy and Past it in the Ubuntu, First of all, open the Youtube in the Ubuntu access this video from within the Ubuntu Youtube, and then copy and Past it will Work otherwise not!
// ----------------Building The TCP Server-----------
#include stdlib.h
#include sys/types.h
#include sys/socket.h
#include netinet/in.h
#include errno.h
#include stdio.h
#include string.h
#include iostream
#include unistd.h
using namespace std;

int main()
{
int fd=socket(AF_INET,SOCK_STREAM,0); //Socket Creation
if(fd==-1)
{
perror("Socket Creation Failed");
exit(-1);
}
else
{
cout "Socket Creation Successful" endl;
}
struct sockaddr_in addr; //Binding
addr.sin_addr.s_addr =INADDR_ANY;
addr.sin_family = AF_INET;
addr.sin_port=htons(83);
if(bind(fd,(struct sockaddr*)& addr,sizeof(addr))==-1)
{
perror("Binding failed on socket:");
}
else
{
cout "Binding Successful" endl;
}
int backlog=10;//Listen
if(listen(fd,backlog)==-1)
{
perror("Listening Failed on Socket:");
exit(-1);
}
else
{
cout "Listening Successful" endl;
}
int connfd; //Accept
struct sockaddr_in cliaddr;
socklen_t cliaddr_len=sizeof(cliaddr);
connfd=accept(fd,(struct sockaddr*)& cliaddr,& cliaddr_len);
char buffer[100];//Message
while(1)
{
int wali=recv(connfd,buffer,100,0);
if (wali==0)
{
close(fd);
close(connfd);
exit(1);
}
cout "Message Received:" buffer endl;
cout "Type the Message:" endl;
fgets(buffer,100,stdin);
send(connfd,buffer,100,0);
}
close(fd);
close(connfd);
return 0;
}
// ----------------Building The TCP Clint-----------
#include stdlib.h
#include sys/types.h
#include sys/socket.h
#include netinet/in.h
#include errno.h
#include stdio.h
#include arpa/inet.h
#include iostream
#include string.h
#include unistd.h
using namespace std;

int main()
{
int fd=socket(AF_INET,SOCK_STREAM,0); //Socket Creation
if(fd==-1)
{
perror("Socket Creation Failed");
exit(-1);
}
else
{
cout "Socket Creation Successful" endl;
}
struct sockaddr_in s_addr; //Connection
s_addr.sin_family = AF_INET;
s_addr.sin_port=htons(83);
inet_aton("127.0.0.1",& s_addr.sin_addr);
connect(fd,(struct sockaddr*)& s_addr,sizeof(s_addr));


char buffer[100];//Message
while(1)
{
cout "Type the Message:" endl;
fgets(buffer,100,stdin);
send(fd,buffer,strlen(buffer),0);
int wali=recv(fd,buffer,strlen(buffer),0);
if (wali==0)
{
close(fd);
exit(1);
}
cout "Message Received:" buffer endl;

}
close(fd);
return 0;
}

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «TCP client server application», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.