乙個簡單的聊天程式 命名管道FIFO

2021-05-28 11:52:49 字數 1000 閱讀 6034

本程式是乙個使用fifo進行程序間通訊的典型程式lucy.c建立了fifo write──fifo用於向程式peter.c傳送資訊:程式建立了fifo read-fifo,用於向lucy.c傳送訊息。編譯本程式,先執行peter.c再執行lucy.c就可以了。

源程式如下:

#include

#include

#include

#include

#include

#include

#include

#include

int main(viod)

write_fd=open(write_fifo_name,o_wronly);

if(write_fd==-1)

while((read_fd=open(read_fifo_name,o_rdonly))==-1)

while(1)

write(write_fd,buf,strlen(buf));

len=read(read_fd,buf,256);

if(len>0)}}

#include

#include

#include

#include

#include

#include

#include

#include

int main(viod)

while((read_fd=open(read_fifo_name,o_rdonly))==-1)

write_fd=open(write_fifo_name,o_wronly);

if(write_fd==-1)

while(1)

printf("peter:");

fgets(buf,256,stdin);

buf[strlen(buf)-1]='\0';

if(strncmp(buf,"quit",4)==0)

write(write_fd,buf,strlen(buf));}}

乙個最簡單聊天程式

客戶端的 include include include include pragma comment lib,ws2 32.lib socket self long chang sockaddr in local1 wsadata data int datareturn bool canrecv ...

Java實現乙個簡單的聊天室程式

以下程式是先執行伺服器端程式,再執行客戶端程式,否則會丟擲異常。1 伺服器端程式 public class server catch ioexception e 接收客戶端輸入的方法 private static void transmitmessage socket socket catch io...

socket例項C語言 乙個簡單的聊天程式

我們老師讓寫乙個簡單的聊天軟體,並且實現不同機子之間的通訊,我用的是socket程式設計。不廢話多說了,先附上 伺服器端server.c include include include include include include include include include include d...