# udp

UDP (User Datagram Protocol) BETA

Author | Matthew Schinkel - borntechi.com, copyright © 2011, all rights reserved.
Adapted-by |
Compiler | >=2.4n

Description

    An unreliable, connection less protocol, used to send and
                 recieve data. The application must provide it's own reliability.

Sources

    http://www.networksorcery.com/enp/protocol/udp.htm

Dependencies

No dependency found

## Summary

### Global variables/contants

- `const UDP_HEADER_SIZE = 8`
- `const word UDP_CHECKSUM = 6`
- `var bit _udp_error = FALSE`
- `var word udp_socket_remote_port[UDP_MAX_SOCKETS]`
- `const word UDP_LENGTH = 4`
- `var byte*4 udp_socket_ip[UDP_MAX_SOCKETS]`
- `var byte _udp_socket_ip[4] at udp_socket_ip`
- `const UDP_NO_SOCKET_AVAILABLE = 1`
- `const UDP_NO_ERROR = 0`
- `const UDP_SOCKET_OPEN = 1`
- `var byte udp_socket_status[UDP_MAX_SOCKETS]`
- `const UDP_SOCKET_CLOSED = 0`
- `const word UDP_SOURCE_PORT = 0`
- `const word UDP_DESTINATION_PORT = 2`
- `var word udp_socket_local_port[UDP_MAX_SOCKETS]`

### Procedures

- `udp_send_array(byte in socket_name, byte in data[])`
- `udp_read_packet()`
- `print_udp_socket_info(bit in receiving_sending, byte in socket)`
- `udp_send(byte in socket_name, word in data_size)`
- `udp_socket_remove(byte in socket_number)`
- `udp_data'put(word in address, byte in data)`
- `udp_init()`

### Functions

- `udp_data'get(word in address) return byte`
- `udp_error'get() return byte`
- `udp_socket_create(word in local_port, word in remote_port) return byte`

## API details

### Global variables/contants

- `const UDP_HEADER_SIZE = 8`

  No documentation found

- `const word UDP_CHECKSUM = 6`

  No documentation found

- `var bit _udp_error = FALSE`

  No documentation found

- `var word udp_socket_remote_port[UDP_MAX_SOCKETS]`

  No documentation found

- `const word UDP_LENGTH = 4`

  No documentation found

- `var byte*4 udp_socket_ip[UDP_MAX_SOCKETS]`

  No documentation found

- `var byte _udp_socket_ip[4] at udp_socket_ip`

  No documentation found

- `const UDP_NO_SOCKET_AVAILABLE = 1`

  No documentation found

- `const UDP_NO_ERROR = 0`

  No documentation found

- `const UDP_SOCKET_OPEN = 1`

  No documentation found

- `var byte udp_socket_status[UDP_MAX_SOCKETS]`

  No documentation found

- `const UDP_SOCKET_CLOSED = 0`

  No documentation found

- `const word UDP_SOURCE_PORT = 0`

      UDP header format

- `const word UDP_DESTINATION_PORT = 2`

  No documentation found

- `var word udp_socket_local_port[UDP_MAX_SOCKETS]`

  No documentation found

### Procedures

- `udp_send_array(byte in socket_name, byte in data[])`

      Sends a UDP packet from an input array (uses more memory space)
      more ram usage and less cpu cycles then udp_send_array()

- `udp_read_packet()`

      Read a UDP packet

- `print_udp_socket_info(bit in receiving_sending, byte in socket)`

  No documentation found

- `udp_send(byte in socket_name, word in data_size)`

      Sends a UDP packet containing data held in udp_data[] array. You
      must specify the size of data written to udp_data[]
      less ram usage and more cpu cycles then udp_send_array()

- `udp_socket_remove(byte in socket_number)`

      Celete/disconnect a socket.

- `udp_data'put(word in address, byte in data)`

  No documentation found

- `udp_init()`

      Init procedure

### Functions

- `udp_data'get(word in address) return byte`

      Fake array udp_data[] to read/write to UDP Data space.

- `udp_error'get() return byte`

      Read udp error status. clears error after reading

- `udp_socket_create(word in local_port, word in remote_port) return byte`

      Create a new socket if one doesn't arleady exist. If a socket already
      exists, return the socket.
      If a socket was not created, var udp_error gets set.
      remote_port - the port number the server uses
      local_port - any port number that is avalable locally.

## Related samples

Here are the list of samples which use this library:

18f4620 | 18f4620_network_all_in_one.jal
18f4620 | 18f4620_network_udp_server.jal
18f4620 | 18f4620_network_slip_isr_ping_udp.jal
18f4620 | 18f4620_network_udp_client.jal