c語言聊天程序
A. 求一個用c語言寫的網路聊天程序,本人菜鳥!
用c語言寫聊天程序比較麻煩,要熟悉許多協議,而且還要知到那些介面的用法,我以前也想寫一個,但只寫到了用tcp/ip協議和埠寫了個簡單的通話程序,而且用c語言寫界面不好,代碼多,如果用其他的語言,如delphi、vb、c#之類的寫就容易多了,如果你想要我這不完善的代碼可以點我名字
-物聯網校企聯盟技術部
B. 關於用C語言開發一個簡單的區域網聊天軟體
linux系統都是C寫的
用C當然行得通
就是個socket編程嘛
我們原來做過一個的原理描述
當然
這個是C\S模式的
其實你可以做成
無服務端的
本系統具有區域網聊天功能。採用了C\S模式(即伺服器創建套接字後,轉換為監聽套接字,一直在監聽是否由客戶端的請求。伺服器接收到相應的請求後,進行相應的處理)。採用了TCP/IP(面向連接)協議。運用了SOCKET套接字實現了很方便的訪問TCP/IP協議。多線程的操作。
伺服器的程序(簡述):
創建socket-->bind()-->listen()-->accept()-->recv/send()-->close();
客戶端的程序(簡述):
創建scoket-->發送connect-->recv/send()-->close();
C. C語言聊天程序 想寫個基於C語言的簡單聊天程序(控制台程序),C/S模式,實現客戶端之間的通信
軟體和伺服器配置好就可以了,最好用PHP+myqsl
D. 求C語言高手,實現一個簡單的TCPIP程序以實現兩台計算機之間的聊天通信,
哥們你電氣幾班的啊。。
E. 用C語言在WIN32下編譯一個簡單的聊天程序,客戶端向伺服器發消息,伺服器接到消息後會返回一個
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<errno.h>
#include<netinet/in.h>
#include<sys/socket.h>
#define SERVERPORT 5555#define BACKLOG 10
#define MAXLEN 1024
int main(){
int sockfd,client_fd;
int sin_size = 0;
int recvlen = 0;
char recvbuf[MAXLEN]={0};
struct sockaddr_in my_addr;
struct sockaddr_in cli_addr;
int iRet;
/*建立socke通信*/
if((sockfd = socket(AF_INET,SOCK_STREAM,0)) == -1){
printf("Create socket error\n\n");
exit(1);
}
printf("socket success\n");
my_addr.sin_family=AF_INET; my_addr.sin_port=htons(SERVERPORT);
my_addr.sin_addr.s_addr=INADDR_ANY;
memset(my_addr.sin_zero,0,8);
/*綁定socket埠*/
if(bind(sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr)) == -1){
printf("bind error\n");
close(sockfd);
exit(1);
}
printf("bind success\n");
/*監聽埠*/
if(listen(sockfd,BACKLOG) == -1){
printf("listen error\n!");
close(sockfd);
exit(1);
}
printf("listren success\n");
while(1) {
sin_size = sizeof(struct sockaddr_in);
/*阻塞等待客戶端發送消息*/
if((client_fd=accept(sockfd,(struct sockaddr *)&cli_addr,&sin_size)) == -1)
{
printf("accept error !");
continue;
}
printf("accept success\n");
printf("receive a connection form %s\n",inet_ntoa(cli_addr.sin_addr));
/*fork進程,子進程處理接收的信息*/
iRet=fork();
if(iRet < 0)
{
printf(" fork err, pid=[%d]", getpid());
}
/*fork返回0,為子進程*/
else if(iRet == 0)
{
printf("pid=[%d]", getpid());
printf("子進程\n");
memset(recvbuf,0,sizeof(recvbuf));
/*接收客戶端發送的內容*/
if((recvlen = recv(client_fd,recvbuf,MAXLEN,0)) == -1)
{
printf("recv error\n");
close(client_fd);
exit(1);
}
printf("recvlen[%d]\n",recvlen);
printf("recvmsg:\n%s\n",recvbuf);
/*向客戶端發送內容*/ if(send(client_fd,recvbuf,recvlen,0) == -1)
{
printf("send error\n");
close(client_fd);
exit(1);
}
printf("sendmsg:\n%s\n",recvbuf);
close(client_fd);
exit(0);
}
/*父進程,返回子進程pid*/
else
{
printf("pid=[%d]", getpid());
printf("父進程\n");
continue;
}
}
close(sockfd);
exit(0);
}
F. 如何用c語言編寫QQ聊天程序(源代碼)
1、首先,我們編寫C語言的頭文件#include <stdio.h>。
G. 如何用C語言編寫一個簡單的聊天室程序
這樣:
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <pthread.h>
#define MAXLINE 100;
void *threadsend(void *vargp);
void *threadrecv(void *vargp);
int main()
{
int *clientfdp;
clientfdp = (int *)malloc(sizeof(int));
*clientfdp = socket(AF_INET,SOCK_STREAM,0);
struct sockaddr_in serveraddr;
struct hostent *hp;
bzero((char *)&serveraddr,sizeof(serveraddr));
serveraddr.sin_family = AF_INET;
serveraddr.sin_port = htons(15636);
serveraddr.sin_addr.s_addr = inet_addr("127.0.0.1");
if(connect(*clientfdp,(struct sockaddr *)&serveraddr,sizeof(serveraddr)) < 0){
printf("connect error ");
exit(1);
}
pthread_t tid1,tid2;
printf("connected ");
while(1){
pthread_create(&tid1,NULL,threadsend,clientfdp);
pthread_create(&tid2,NULL,threadrecv,clientfdp);
}
return EXIT_SUCCESS;
}
void *threadsend(void * vargp)
{
//pthread_t tid2;
int connfd = *((int *)vargp);
int idata;
char temp[100];
while(1){
//printf("me: ");
fgets(temp,100,stdin);
send(connfd,temp,100,0);
printf(" client send OK ");
}
printf("client send ");
return NULL;
}
void *threadrecv(void *vargp)
{
char temp[100];
int connfd = *((int *)vargp);
while(1){
int idata = 0;
idata = recv(connfd,temp,100,0);
if(idata > 0){
printf("server : %s ",temp);
}
}
return NULL;
}
(7)c語言聊天程序擴展閱讀:
注意事項
linux下編譯多線程代碼時,shell提示找不到 pthread_create函數,原因是 pthread.h不是linux系統默認載入的庫文件,應該使用類似如下gcc命令進行編譯:
gcc echoserver.c -lpthread -o echoserver
只要注意 -lpthread參數就可以了。
H. 用C語言寫一個簡單聊天軟體!謝謝
聽了樓上的我都不敢說Windows程序設計中的SDK用的也是c語言了
傳的是《C語言高級編程及實例剖析》中的第六章的源碼,用的是SDK編程,裡面拉了控制項和用了多線程
樓主如果需要界面比較復雜的聊天室程序,用MFC當然方便點,但用SDK也沒有太大的問題(原理是一樣的,學哪一種,另一種就會了)。後者的教程貌似很難找。可以看看MFC的,比較好的是 《Vc++ 打造區域網聊天室》(視頻)
兩種資料在網上都找得到...
補充:當然,如果需要傳文件,圖片那些,就需要研究研究網路協議了,也只是添加些功能而已