# Poco::Net

# class UDPClient

Library: Net
Package: UDP
Header: Poco/Net/UDPClient.h

## Description

UDP client can either send, or send/receive UDP packets. The mode of operation is specified at construction time. If receiving functionality is enabled, it will run in a separate thread. This class is written as a "companion" to Poco::Net::UDPServer. For other servers, inherit from this class and override the handleResponse(char*, int) virtual member.

## Inheritance

Direct Base Classes: Poco::Runnable

All Base Classes: Poco::Runnable

## Member Summary

Member Functions: address, dataBacklog, errorBacklog, getOption, handleResponse, peerAddress, run, send, setOption, stop

Inherited Functions: run

## Constructors

### UDPClient

UDPClient(
const std::string & address,
Poco::UInt16 port,
bool listen = false
);

Creates UDP client and connects it to specified address/port. If listen is true, a thread is launched where client can receive responses rom the server.

## Destructor

### ~UDPClient

virtual ~UDPClient();

Destroys UDPClient.

## Member Functions

### address

SocketAddress address() const;

Returns client address.

### dataBacklog

int dataBacklog() const;

Returns current server data backlog.

### errorBacklog

int errorBacklog();

Returns current server error backlog.

### getOption

int getOption(
int opt
);

Returns socket option.

### handleResponse

virtual int handleResponse(
char * buffer,
int length
);

Handles responses from UDP server. For non-POCO UDP servers, this function should be overridden in inheriting class.

### peerAddress

SocketAddress peerAddress() const;

Returns server address.

### run

void run();

Runs listener (typically invoked internally, in separate thread).

See also: Poco::Runnable::run()

### send

int send(
void * data,
int length
);

Sends data.

### send

int send(
const SocketBufVec & vec
);

Sends data.

### setOption

void setOption(
int opt,
int val
);

Sets socket option.

### stop

void stop();

Stops the server reply receiving thread, if running.