Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 153265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:46:15+00:00 2026-05-11T09:46:15+00:00

I am writing a Tomcat app. As part of its functionality, it needs to

  • 0

I am writing a Tomcat app. As part of its functionality, it needs to send out a UDP multicast when certain events happen. Right now my code goes something like this (host and group are fake, exception handling ripped out to save space):

import java.net.*; /* ..... */ DatagramSocket socket = new DatagramSocket(12345); InetAddress group = InetAddress.getByName('111.222.333.444'); DatagramPacket packet = new DatagramPacket(buf, buf.length, group, 12346); socket.send(packet); 

This works fine when I install it into tomcat; however, when I try to install a new version of the app (using ‘ant remove; ant install;’), I fail to bind to a socket, and get a java.net.BindException: Address already in use. The only way out is to restart Tomcat every time, which is obviously unacceptable. How do I use sockets in a Tomcat-friendly way?

A couple of clarifications per Pete’s answer:

I don’t close the socket; it lives in a Singleton. Adding a method that can close the socket to the Singleton and calling it in the servlet’s destroy worked, thank you! It’s a bit hacky, I think (exposing a method like that to the world via a public method), but it gets the job done.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:46:15+00:00Added an answer on May 11, 2026 at 9:46 am

    Are you closing the socket after you use it via disconnect() / close()? What is the lifecycle on the socket – per request, or a singleton? If it is per request, closing the socket should release it. If a singleton, you’ll need to somehow close it on ‘ant remove’ – if shutting down / restarting Tomcat is not acceptable, then perhaps your ant script can call some secure page, etc. that closes the socket. If you can incur a shutdown restart, then close the socket in the servlet’s destroy() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing JSP pages and using Tomcat, and it needs to work for IE
I'm writing a Java Tomcat intranet app that uses NTLM to lookup a user's
I'm creating my first Spring MVC app on Tomcat 6. Certain pages will be
I am writing a web application (Tomcat 7) so no JTA and want to
I'm writing a bash script that automatically deploys an application to a tomcat server.
I am writing a JSF 2.0 Mojarra application using Primefaces 3.3.1 on Tomcat 6.
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
I've been attempting to pull hard-coded configuration data from a Tomcat web-app which I'm
I'm writing a backend for a mobile web-app based in Java and I was
I'm writing a java application that runs in Tomcat, on a multi-core hardware. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.