📄 unixclient.c
字号:
/* unixClient - send an integer to the vxWorks server *//* Copyright 1984-1994 Wind River Systems, Inc. *//*modification history--------------------01b,05dec94,bss cleaned up. WRS coding conventions enforced. 01a,???????,??? written.*//*DESCRIPTIONThis module provides a simple example of the issues involved insending data between different machines: these machinesmight store data with different byte orderings, structurealignments, floating-point representations, etc.In this example, we are only sending an integer to the server sowe will only deal with byte ordering. The client convertsthe data from a machine-dependent byte-orderingto a standard representation (network byte ordering) andsends the data to the server. The server then converts the datafrom the standard representation to the machine-dependentrepresentation on the server. Finally the server sendsa reply to the client.NOTE: This code was written in the pre-ANSI style to facilitate compilation with the native Sun compiler cc. To compile this code with an ANSI compiler, use the -traditional flag.*//* includes */#include <stdio.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>/* defines */#define MAX_MSG_LEN 80#define LOCAL static /* for WRS coding conventions *//* typedefs */typedef int SOCK_FD;/* forward declarations */LOCAL void error();/******************************************************************************* * * main - entry point to unixClient * * This function sets up a socket and send an integer in * network byte ordering to vxServer. This is a simple * example of the issues of data representation which * are encountered in network programming. */main (argc, argv) int argc; char **argv; { short port; /* Server's port number */ int inetAddr; /* Server's inet address */ struct sockaddr_in srvAddr; /* Server's socket address */ int val; /* Value to send the server */ SOCK_FD sockFd; /* Client's socket */ char replyBuf [MAX_MSG_LEN]; /* Place to put the server's reply */ /* Get the server port number, inet address, and value to send */ if (argc != 4) { fprintf (stderr, "Usage: %s portNumber inetAddress value\n", argv[0]); exit (1); } port = (short) atoi (argv [1]); inetAddr = inet_addr (argv [2]); val = atoi (argv [3]); /* Create a socket */ /* Initialize servers address */ /* Send the server the value */ /* Read and then print the servers reply */ /* Close socket */ }/******************************************************************************* * * error - aborts a process on an error * * This funcion displays the reason a process crashed * and terminates that process. */LOCAL void error (pStr) char * pStr; { perror (pStr); exit (1); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -