socket网络编程,写一个Helloworld程序

来源:百度知道 编辑:UC知道 时间:2024/05/07 19:39:53
socket网络编程,写一个Helloworld程序,包括client和server两部分

/*分别编译client.c server.c*/

/*use*/
/*1.先运行server*/
/*D:\>client /? */
/*2. D:\>client -p:5150 -s:192.168.99.77 -n:5 */

/*server.c*/
// Module Name: Server.c
//
// Description:
// This example illustrates a simple TCP server that accepts
// incoming client connections. Once a client connection is
// established, a thread is spawned to read data from the
// client and echo it back (if the echo option is not
// disabled).
//
// Compile:
// cl -o Server Server.c ws2_32.lib
//
// Command line options:
// server [-p:x] [-i:IP] [-o]
// -p:x Port number to listen on
// -i:str Interface to listen on
// -o Receive only, don't echo the data back
//
#include <winsock2.h>

#include <stdio.h>
#include <stdlib.h>
#pragma comment (lib,"ws2_32.lib")
#define DEFAULT_PORT 5150