[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
UDP network communication
Date: Wed, 8 Jul 1992 12:16 EDT
From: email@example.com (Robin Kladke (303-977-9670))
Are there any good example files laying around that would help me put
together a program to send binary data using UDP to a Sun?
See the end of this message; this is an example I consed up based on some application
code I wrote a while back.
I have 3 problems
i am trying to tackle: (1) setting up the UDP communication, (2) parsing
incoming binary data into appropriate internal data structures as well as
structuring outgoing data, and (3) byte-swapping. I am currently stuck on the
first and i believe the primary reason to be that there are not many UDP
examples in the Network manual. For test purposes, I am using a 3630 and
XL400 running under Genera 8.1. Once i get the UDP working between those two,
i will attempt to communicate between the '30 and a Solbourne running under
UNIX (actually OS/SMP 4.0D_Export or some such).
I am including my code along with the sample application i have been using to
test it. This code does not worry the binary problem or the byte swapping; it
just tries to get the machines to talk to each other using UDP. Some functions
are defined twice so that i can use the simpler version for testing.
My primary problem seems to be that the data is not being packaged correctly.
The starting and ending index of the message received is always 8 and 8.
This sounds like you are not sending any arguments with the data; the array you get
is the real packet; the 8 bytes at the beginning are overhead bytes of the header,
you only get to see the argument bytes that were passed.
Should i be sending an array? The few examples do not indicate that. I have
tried sending a string and an integer. Neither gets there. Should i explicitly
be sending size information?
I want to use the response-array for the ACK. I didn't find i really needed
the start and end indices. Do i really need to set these?
In your code you only set them inside a function, where they were local variables
and were lost. I used the other option mentioned in the documentation, namely
to return the string I want as an answer and let the system copy it into the array.
;;; -*- Mode: LISP; Syntax: Common-lisp; Package: USER; Base: 10 -*-
(neti:invoke-service-on-host :binary-udp neti:*local-host* "testing")
"what you sent from host WESER was: ->testing<-"
(chaos:add-contact-name-for-protocol :binary-udp) ;for use over CHAOS
(tcp::add-udp-port-for-protocol :binary-udp 501) ;for use over TCP
(neti:define-server :binary-udp (:medium :datagram :simple-p t
:request-array (array start limit))
(si:make-array (- limit start) :type'si:art-string
(string-append (format nil "what you sent from host ~A was: ->" host)
(neti:define-protocol :binary-udp (:binary-udp :datagram)
:rfc-data (first (neti:service-access-path-args neti:.service.)))
(binary-udp-simple stream request)))
(defun binary-udp-simple (stream request)
(multiple-value-bind (buffer start limit)
(send stream :read-input-buffer)
((size (- limit start))
(si:make-array size :type'si:art-string :displaced-to
buffer :displaced-index-offset start)))