Instructions : all home assignments are to be completed in groups of



Download 219,74 Kb.
Pdf ko'rish
bet16/17
Sana12.11.2022
Hajmi219,74 Kb.
#864723
1   ...   9   10   11   12   13   14   15   16   17
Bog'liq
SOC3010 OS HOME ASSIGNMENT 3 FALL 2022

int read_size;
char message[2000] , client_message[2000], schat[2000], *bye, s[10], chat[2000], s1[100];
bye = "bye";
//Send some messages to the client
strcpy(message, "To ");
sprintf(s, "%d", sock);
strncat(message, s, strlen(s));


SOC3010 OPERATING SYSTEMS 
HOME ASSIGNMENT 3 
FALL 2022
strcpy(s1, " : Greetings! I am your connection handler\n");
strncat(message, s1, strlen(s1));
write(sock , message , strlen(message));
memset(message, 0, sizeof(message));
read_size = read(sock , client_message , strlen(client_message));
printf("From Client [%d] : %s \n", sock, client_message );
strcpy(message, "To ");
sprintf(s, "%d", sock);
strncat(message, s, strlen(s));
strcpy(s1, "Now we shall have a chat session : so type something \n");
strncat(message, s1, strlen(s1));
write(sock , message , strlen(message));
//Receive a message from client
while(1)
{
memset(client_message, 0, sizeof(client_message));
read_size = read(sock , client_message , strlen(client_message));
printf("From Client [%d] : %s\n", sock, client_message );
memset(schat, 0, sizeof(schat));
printf("server : ");
fgets (schat, sizeof(schat), stdin);
strcpy(chat, "To ");
sprintf(s, "%d", sock);
strncat(chat, s, strlen(s));
strncat(chat, schat, strlen(schat));
send(sock, chat , strlen(chat) , 0 );
schat[strlen(schat)] = '\0';
if(strncmp(schat , bye, strlen(bye))==0)
break;
}
puts("Client disconnected");
fflush(stdout);

Download 219,74 Kb.

Do'stlaringiz bilan baham:
1   ...   9   10   11   12   13   14   15   16   17




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish