connecting to a tcp server and sending udp

i am working on a project in witch i need to pres a button and send a message to a server/port via TCP and then send a UDP packet to a separate server/port.
i can get both setups to work, the TCP connection works fine.
and the UDP works fine.
when i try to do both i get nothing.
i can send to the TCP connection up in til i try to send the udp packet.
any thoughts. is this even able to be done.
do i need to close the TCP connection to send the UDP packet then reopen the TCP connection again?

Are you trying to maintain a persistent tcp connection when you attempt to send the UDP packet? If so, I haven't tried to use UDP with a tcp connection open. Maybe you should post the code you are using.

yes i am trying to keep the TCP connection open.
my tcp server is kinda slow and i don’t have time to close and reopen the connection.

It will send and receive a UDP packet while the tcp connection is open. I just tested it.

in your test did the udp packet go to the same or a different ip then the TCP connection was made to.

I have a few servers, so I tried the same IP and different IPs. Both worked.

edit: Do you know if it is the send or the receive that fails?

it is the send that fails.
if i send the tcp packet it gets through.
then it sends the UDP packet. that fails
then i can no longer send to the tcp conection

Post the code you are using. I'll give it a try and see if I can get it working.

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>   

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,251,201);

// Enter the IP address of the server you're connecting to:
IPAddress server(192,168,251,53); 

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 23 is default for telnet;
// if you're using Processing's ChatServer, use  port 10002):
EthernetClient client;

const int DMX_Universe=0;//universe is from 0 to 15, subnet is not used
const int number_of_channels=512; //512 for 512 channels, MAX=512

byte destination_Ip[]= {   255,255,255,255 };
unsigned int localPort = 6454;

//ART-NET variables
char ArtNetHead[8]="Art-Net";
const int art_net_header_size=17;

short OpOutput= 0x5000 ;//output

byte buffer_dmx[number_of_channels]; //buffer used for DMX data

EthernetUDP Udp;

//Artnet PACKET
byte  ArtDmxBuffer[(art_net_header_size+number_of_channels)+8+1];

void setup() {
  // start the Ethernet connection:
  Ethernet.begin(mac, ip);
 // Open serial communications and wait for port to open:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  // give the Ethernet shield a second to initialize:

  // if you get a connection, report back via serial:
  if (client.connect(server, 5250)) {
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");

void loop()
  if (client.available()) {
    char c =;

  // as long as there are bytes in the serial queue,
  // read them and send them out the socket if it's open:
  while (Serial.available() > 0) {
    char inChar =;
    if (client.connected()) {
       client.println("PLAY 1-7 \r\n");
       delay (40);

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    // do nothing:

void construct_arnet_packet()

     ArtDmxBuffer[9]= OpOutput >> 8;
     ArtDmxBuffer[13] = 0;
     ArtDmxBuffer[14]= DMX_Universe;//or 0
     ArtDmxBuffer[15]= DMX_Universe>> 8;
     ArtDmxBuffer[16] = number_of_channels>> 8;
     ArtDmxBuffer[17] = number_of_channels;
     for (int t= 0;t<number_of_channels;t++)
void Send_Artnet_data()
   Udp.beginPacket(destination_Ip, localPort);
   Udp.write(ArtDmxBuffer,(art_net_header_size+number_of_channels+1)); // was Udp.sendPacket

so this code alows me to send any thing to it over serial and it will send commands to the two servers/ports.

I don't see a udp.begin call in setup.

added that back in.
still have the same problem.

i stand corrected,
it does maintain the tcp connection now.
so i just need to analyse my udp packet and see why it is not getting there.

one line of code missing...
i have got it working now thanks.

i feel dumb.

Hello jyeomans

i've a similar problem, see my topic please, :confused:

And like you SuferTim try to help me, very nice of him !

at the end of your topic , you say "one line of code missing... "
so i'm very curious on this "line of code..." cause it could be very helpful for my problem :stuck_out_tongue: