编写基于Socket的网络服务程序和客户程序(高分哦)

来源:百度知道 编辑:UC知道 时间:2024/09/21 22:29:24
编写基于Socket的网络服务程序和客户程序,完成客户与服务器之间的消息传输等功能,要求:
(1) 基于UDP传输控制台输入的字符串, 基于 TCP传输字节数。

(2) 服务器使用多线程技术。

(3) 使用标准C语言,不能使用面向对象编程。

(4) 服务器端口使用自己学号的最后四位。

大家帮帮忙,我留个邮箱,谁有这方面的程序发给我看看,再加100分...
peidashuai@163.com

基于UDP传输控制台输入的字符串, 基于 TCP传输字节数

不难 但是上边这句不知道是什么意思

udp 传输的是字符串, 什么tcp传输字节数(我理解,串长度的值用tcp传输)

我写出来了,我qq230635800

我在qq上给你发吧

服务器:
#include <string.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>

#define LINE 2048

pthread_mutex_t work = PTHREAD_MUTEX_INITIALIZER;

struct sockaddr_in tcpsock, udpsock;

void *handle_tcp(void *arg)
{
int tcpfd = *((int *)arg);
int tcpcon;
int n;
char *suc = "success";
socklen_t len = 0;
struct sockaddr_in tcpcli;
listen(tcpfd, 20);
char str[INET_ADDRSTRLEN];
char buf[LINE];

while(1)
{
len = sizeof(tcpcli);
tcpcon = accept(tcpfd, (struct sockaddr*)&tcpcli, &len);
pthread_mutex_lock(&work);
printf(