c winsock

来源:百度知道 编辑:UC知道 时间:2024/05/14 04:32:46
各位高人,俺最近开始看c的网络通讯,编写了一个简单的程序,但是老报错,帮忙看看,多谢。
client.c 客户端发信
/*
* Client.c
*
* Created on: 2009/04/17
* Author: gas
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <Winsock.h>
//#include <Winsock2.h>
#include <errno.h>

#define LOCALHOST "127.0.0.1"
#define PORT_NO 1234

static SOCKET c_sock;

int main( int argc, char *argv[] ){

WSADATA wsadata;
struct sockaddr_in user_addr;
char tmp[256];
char buf[256];
BYTE buf2[256];
//struct hostent *shost;

memset(&user_addr, 0x00, sizeof(user_addr));
memset(&tmp, 0x00, sizeof(tmp));
memset(&buf, 0x00, sizeof(buf));
//shost = gethostbyname( argv[1] ) ;
//printf("%s \n",argv[1]);
//printf("%s %s %d\n",argv[1],shost->h_addr_list,shost->h_length);

server.c服务器端
/*
* Client.c
*
* Created on: 2009/04/17
* Author: gas
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <Winsock.h>
//#include <Winsock2.h>
#include <errno.h>

#define LOCALHOST "127.0.0.1"
#define PORT_NO 1234

static SOCKET s_sock;

static int sock_size;
int main( int argc, char *argv[] ){

WSADATA wsadata;
struct sockaddr_in server_addr;
struct sockaddr_in user_addr;

char tmp[256];
char buf[256];
struct hostent *shost;

memset(&server_addr, 0x00, sizeof(server_addr));
memset(&user_addr, 0x00, sizeof(user_addr));
memset(&tmp, 0x00, sizeof(tmp));
memset(&buf, 0x00, sizeof(buf));

shost = gethostbyname( argv[1] ) ;

if(argc < 3)
{
//printf("Client serverip port\