Windows and DOS (client) network interconnect based on TCPIP programming implementation

zhaozj2021-02-08  217

1. Under the development of network technology, the application of Lin network is low, fast, and so on. Since the client is in the mall POS or industry site usually uses a DOS environment (due to facts and easy-to-operate hardware, And occupying less disk space), and use Win9X development in server-side design and friendly user interface: Win9X-side implementation adopts popular Win9x network settings to programmatically, you can use VB writing server Interface implementation, this system uses TCP protocol. The specific implementation is relatively simple, there is a large number of examples. 4: DOS-side network settings

DOS client needs to install MS-Client for MSDOS (Winnt4 CD, netbook for DOS Times)

Sockets.exe socket driver loading MS Client for DOS in AutoExec.bat

AutoExec.bat file

C: /net/neetbind.comc: /net/umb.comc: /net/tcptsr.exec: /net/tinyrfc.exec: /net/nmtsr.exec: / net / emsbfr. EXEC: / NET / NET START

Modify the TCPUTILS.INI file under the NET directory, plus hostname = localhost in the [TCPGlobal] segment (your machine name)

5: DOS-side software design uses the TCP protocol routine as follows:

// Development environment: DOS622 BC 3.1

/ ************************************************** File Name: Client. C Develop member: Wu Jianping function: DOS client send message last modified: 2001-08-20 *************************** **************** /

// Server Name Send #include #include #include #include #include #include #include #include #include #include #include #include

#define buffer_size 1000 # Define line_len 70 # define ini_file "netsend.ini"

Char sendbuf [buffer_size]; char recvbuf [buffer_size]; struct sockaddr_in server_addr, client_addr;

INT F_GETINIKEY (CHAR * FNAME, CHAR * Section, Char * Key, Char * Value); int Sleep (INT Seconds) {long start_seconds, current_seconds, end_seconds;

Time (& Start_Seconds); End_seconds = Start_seconds (long) Seconds;

DO {TIME (& current_seconds);} while (current_seconds / n", argv [0]); exit (1);}

/ ************************************************** ************* * Read the machine IP address from the configuration file ***************************** *********************************************************** / MEMSET (LS_SERVER_IP, 0x00, SIZEOF (LS_SERVER_IP)); if (f_getinikey (INI_FILE, "Server", "IP", LS_SERVER_IP) <= 0) {Printf ("Take the server address configuration file [netsend.ini] error / N "); exit (1);} MEMSET (ls_localhost_name, 0x00, sizeof (ls_localhost_name)); if (f_getinikey (INI_FILE," LocalHost "," Hostname ", LS_LOCALHOST_NAME) <= 0 {Printf (" Take this machine address Over the configuration file [NetSend.ini] error / N "); exit (1);}

/ *

** Establish a local communication endpoint * /

SD = Socket (AF_INET, SOCK_STREAM, 0); IF (SD <0) {Printf ("Error: socket () call failed W / RC =% D, Errno =% D / N", SD, Errno); EXIT 1);} printf ("Socket () returns% D / N", SD);

/ *

** Fill the Socket address structure with the necessary information

** Remote server node (introduced remote node IP address and port) Try a server

** Call the Until loop until the remote server is successful or timeout

* /

Server_addr.sin_family = AF_INET; Server_Addr.sin_Port = HTONS (6000); Server_addr.sin_addr.s_addr = inet_addr (ls_server_ip);

Rc = Connect (SD, STRUCKADDR *) & Server_addr, SizeOf (Server_ADDR)); if (RC <0) {Printf ("Error: Connect () call failed w / errno =% d / n", errno); Close_Socket (SD); exit (1);} Printf ("OK 0x% lx / n", server_addr.sin_addr); // Seconds = ATOI (Argv [4]); seconds = 1; printf ("Wait% D Second Before sending data ... / n ", seconds); SLEEP (Seconds); / * ** send the number of bytes specified on the command line to the server. * /

// for (i = 0; i

For (i = 1; i

// STRCPY (Sendbuf, "Hello, Server!"); size = strlen (sendbuf); len = send (SD, SENDBUF, SIZE, 0);

Total = 0; Printf ("Try reception data / N"); do {len = recv (SD, & Recvbuf [Total], Size-Total, 0); if (len <0) {Printf ("error: RECV ( ) Call failed w / errno =% d / n ", errno); Close_Socket (SD); exit (1);} Printf (" RECV () Returns% D byte / n ", LEN); Total = LEN; WHILE (Total <2);

Printf ("Receive Buffer: / N"); for (i = 0; I

/ * * * After all data transfer is complete, turn off the socket and exit after. * / Close_socket (sd); exit (0); return;}

In the project file, you need to include dos_socket.lib, in the mircrosoft TCP / IP SDK for DOS 1.0

Microsoft's development kit (Microsoft provides) Compare Socket development for TCP / IP

Microsoft TCP / IP Sockets Development Kit 1.0 for DOS & Windows Development Pack

http://www.9cbs.net/develop/Article/files/mstcpsdk.rar (thank Guo Hongjun help upload)

CoolStar is modified to 2002-07-02

转载请注明原文地址:https://www.9cbs.com/read-3314.html

New Post(0)