AMX DESIGN XPRESS V 1.5 - PROGRAMMER GUIDE User's Guide Page 45

  • Download
  • Add to my manuals
  • Print
  • Page
    / 316
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 44
KwikNet Overview
K
A
DAK
31
The client calls kn_socket() to create a streaming socket. It then calls kn_bind() to
bind itself to the socket, allowing KwikNet to assign a port number and IP address.
The client then calls kn_connect() to connect to the server with port number 5001 and
IP address 192.168.1.73. Note that the client has to know the port number of the server
to which it is trying to connect. The IP address of the server happens to be the IP address
assigned to the Ethernet network predefined in the
KwikNet Library. The sample
illustrates the use of procedure
kn_inet_addr() to convert an IP address in dotted
decimal form to an equivalent network compatible form.
Once the connection has been established, the client sends the long value 26 (defined as
SAMMSGSZ) as a 4 byte message to the server. The number SAMMSGSZ is the number of
data bytes which the client intends to send to the server. It happens to be the number of
characters in the alphabet, the data which will be sent.
The client then uses procedure kn_recv() to receive a 4 byte message, a long value
which confirms the length of the block of data which the server is willing to accept from
the client.
The client then prepares to send the 26 characters of the alphabet to the server. The client
does so using the kn_writev() procedure which permits the data to be gathered from
disjoint locations in memory but delivered as a sequential byte stream. The 26 characters
are gathered from the following two strings: 10 from the first and 16 from the second.
"ABCDEFGHIJ1234"
"KLMNOPQRSTUVWXYZ5678"
The client then waits for an echo from the server of the data actually received by the
server. The client does so using the kn_readv() procedure which permits the received
data to be scattered into disjoint locations in memory even though received as a
sequential byte stream. The data is scattered into a zero filled character buffer: 7 bytes at
offset 0, 11 bytes at offset 20 and 8 bytes at offset 40. The three strings at offsets 0, 20
and 40 are then expected to match as follows.
"ABCDEFG"
"HIJKLMNOPQR"
"STUVWXYZ"
Finally, the client uses kn_shutdown() to terminate all send operations on its connected
socket and then repetitively calls kn_recv() until all unexpected data, if any, from the
server has been discarded. The socket is then closed using kn_close().
Page view 44
1 ... 44 45 46 ... 316

Comments to this Manuals

No comments