?? 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.
*/
/*
DESCRIPTION
This module provides a simple example of the issues involved in
sending data between different machines: these machines
might store data with different byte orderings, structure
alignments, floating-point representations, etc.
In this example, we are only sending an integer to the server so
we will only deal with byte ordering. The client converts
the data from a machine-dependent byte-ordering
to a standard representation (network byte ordering) and
sends the data to the server. The server then converts the data
from the standard representation to the machine-dependent
representation on the server. Finally the server sends
a 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 + -