How can I listen on 2 ports in 1 app

Here's a synapse of what I'm doing. I'm working on a graphical console program. Basically, I created a GUI interface, for a command prompt program. I'm basically trying to create a command prompt for the new millennium. It allows for multi-connections, has drop-down auto completes, syntax highlighting, object-oriented design, etc. I created it as a multi-threaded server and allows for remote and local connections. The way I have it designed is there are 2 main programs. The graphical client program and the server program. The server program is started whenever the client is started and accepts connections on port 9671. The graphical client can connect to local and remote machines. The client also can store information for multiple sessions in a single window which the user can juggle between. I decided that the server will consist of multiple programs similar to a Linux shell. Rather than build all the commands into the server I can create multiple programs for the server. Once the user needs to do something like copy a file I can call the File program, pass it the info, and have it handle the routine. I decided to have it where once the program is called it will connect to the main server on port 9672 so they can communicate. So what I'm wondering is how can I start my main server on 9671 and allow for connections on port 9672? Remember since I allow for multiple connections I need to be able to find out which thread started the session. I'm thinking either when I call the File program I can pass some thread id so it knows which program called it or I can create another program which runs on port 9672 and I can use the main program as a buffer between itself and the other server? Sorry for the long winded explanation but when I give too little info I usually get people asking me why I'm trying to do it:
<CODE>
package directlinkserver;
import java.io.*;
import java.sql.*;
import java.net.*;
import java.util.*;
public class DirectLinkServer {
static int portOpen1 = 9671;
public static void main(String[] args) {
try {
ServerSocket portListener1 = new ServerSocket(portOpen1);
DirectLinkServer userThreads = new DirectLinkServer();
while (1 == 1) {
Socket userConnection = portListener1.accept();
userThreads.new PortConnection(userConnection);
catch (Exception e) {
System.out.println (
"The server encountered a serious error. Server shut down.");
e.printStackTrace();
System.exit(0);
class PortConnection extends Thread {
Socket ourConnection;
BufferedReader serverInput;
PrintWriter serverOutput;
PortConnection(Socket userConnection) {
try {
ourConnection = userConnection;
serverInput = new BufferedReader(new InputStreamReader(userConnection.getInputStream()));
serverOutput = new PrintWriter(userConnection.getOutputStream(),true);
start();
} catch (Exception e) { System.out.println("An error occurred when a user attempted a connection."); }
public void run() {
serverOutput.println("Welcone to the Server.");
try {
serverOutput.close();
serverInput.close();
ourConnection.close();
} catch (Exception ex1) {}
public void commandConnect() {
</CODE>

Well, I'm still going to ask that. What's wrong with just using the one port? Also, your design seems questionable. How will the server know to start when the client starts, if the server isn't running already and listening on the appropriate port? It's a chicken and egg problem, and generally (every single case I can think of) the server just sits and runs, whether or not there are any clients.

Similar Messages

  • How can I listen to pandaro while exploring other apps

    How can I listen to pandaro while exploring other apps

    I'm guessing you mean "Pandora". Launch Pandora. Start listening to music. Tap the Home button. Select whatever app you want to work with.

  • How can I split the video port of an older Mac Mini so I can use both the 922-6199 DVI to RCA, S-Video Adapter and a Cinema Display?

    How can I split the video port of an older Mac Mini so I can use both the 922-6199 DVI to RCA, S-Video Adapter and a Cinema Display?

    Which exact Mini?
    At the Apple Icon at top left>About this Mac.
    Then click on More Info>Hardware and report this upto but not including the Serial#...
    Hardware Overview:
    Model Name: iMac
    Model Identifier: iMac7,1
    Processor Name: Intel Core 2 Duo
    Processor Speed: 2.4 GHz
    Number Of Processors: 1
    Total Number Of Cores: 2
    L2 Cache: 4 MB
    Memory: 6 GB
    Bus Speed: 800 MHz
    Boot ROM Version: IM71.007A.B03
    SMC Version (system): 1.21f4

  • My computer crashed necessitating re-install of op sys and all programs including iTunes. At the iTunes store when I click a song in my library get error message "can't find, do you want to search?" What's happening? How can I listen to my library on this

    My computer crashed necessitating re-install of operating sys and all programs including iTunes. When I click on a song in my library I get an error message "can't find this song, want to search?" What gives? How can I listen to songs in my library on this computer now?

    It is working now. I no longer get the message about the item not being available in the US and I can access the store.

  • If I imported a CD into my iTunes library from one computer how can I listen to it from another computer?

    If I imported a CD into my iTunes library from one computer how can I listen to it from another computer?  I imported music from a CD into my compter at work and when I got home and went to my iTunes account none of the songs were in my library.  I also noticed that on my Work computer there were a couple songs that I had to click on the little 'cloud' icon before I could listen to them (these were not songs I imported they were songs that were already in my library).  Not sure if this makes semse...help.

    jamie171 wrote:
    My question is since I have imported them into my iTunes library from one computer why can't I access them from my iTunes library from another computer that I have authorized to access whats in my library?  Is there no way to import songs only once into the library and then access them from all my authorized computers?
    Only if you have iTunes Match or of the computers are on the same local network.

  • How can I listen to music from iphone 4s via apple tv whilst doing a phone call at the same time?

    How can I listen to music from iphone 4s via apple tv while doing a phone call at the same time?
    When I take a call on the iphone, iphone stops streaming the music to apple tv until I finished the call.
    thx!
    Claus
    PS: did ask the same question to apple hotline in germany. Answer: we don´t know... funny

    Welcome to the Apple Community.
    As far as I know you can't, which sort of makes sense, it seems logical to pause whatever you are doing while you take a phone call, which after all is the primary function of a phone.

  • How Can I listen to the line-in on my T400?

    When I am at my desk, I've always had my satellite radio plugged into the line-in on my computer so that I can listen to it through the same speakers.  With my new T400, I have the radio's output plugged into the line-in on the Advanced Dock.  I know that it's getting a signal because if I record with Microsoft Sound Recorder, it records the radio.  
    How can I listen live to the signal coming into the line-in?

    You can thank Microsoft for this one.  They disabled the pass-through ability in Vista. Apparently too many people complained about feedback issues when trying to use webcams or VOIP programs and didn't know to mute the Line-In on the mixer.  It took me forever to find how to correct it.
    The following will enable the input sliders in your playback devices so audio pass through works without having to run through an application like it worked in XP. Remember, always backup your Registry just in case. I had to create new Keys for filter and SpeakerHp but yours may already be there
    1) Open regedit (Start->Run, type regedit)
    2) Navigate to HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E96C-E325-11CE-BFC1-08002BE1031*8}\0000\Settings\filter\SpeakerHp\
    3) Create a new Binary Value
    4) Give it the name EnableInputMonitor
    5) Set it's value to 01
    6) Restart your machine
    7) Open your Playback Devices (right click on volume control icon in system tray, select Playback Devices)
    8) Open the Speakers/Headphones
    9) Go to the levels tab
    10) Unmute the input monitor
    T500 - P8600 2.4Ghz Core 2 Duo, Modded - 4GB Patriot DDR3 and 320GB Caviar Black 7200rpm drive with Ati HD3650 and Catalyst 9.6 modded drivers - Vista Business 32bit stripped down to bare bones with VM's from Ubuntu to Win7RC1 64-bit.

  • I would like to create a playlist of some of my voicememos to hear on my iphone5. I have no problem creating the list and can listen on playlist on computer but not when i sync to my phone. How can I listen to voicememos in a playlist on my iPhone?

    I would like to create a playlist of some of my voicememos to hear on my iphone5. I have no problem creating the list and can listen on playlist on computer but not when i sync to my phone. How can I listen to voicememos in a playlist on my iPhone?

    Hi czigrand,
    Thanks for visiting Apple Support Communities.
    Currently, you can gift dollar amounts or individual items (EG. songs) on the iTunes Store. See this article for more information:
    In the iTunes Store, you can gift a dollar amount or specific music, movies, TV shows, or apps from your iPhone, iPod touch, iPad, Mac, or PC. Follow these steps to send a gift from the iTunes Store.
    iTunes: Sending iTunes Gifts
    http://support.apple.com/kb/HT2736
    Best Regards,
    Jeremy

  • How can I listen to itunes and play a game at the same time on my ipad 4?

    How can I listen to itunes and play a game at the same time on my ipad 4? This means I need to run 2 apps at the same time itunes and my game.  The game has its own sound control so I can turn off its sound while i listen to itunes tracks.  But I don't know how to set it up so the ipad does both.

    Anytime you open an app that has a persistant sound stream - a movie, a podcast, some games - it will overide the music app's stream. nothiong you can do to change it.

  • How can you listen to music and play a game at the same time?

    How can you listen to music and play a game at the same time?
    I am playing music, by starting the Crash Baandicoot Nitro Kart 3D game it shuts off the music playing. Is there a way around this?
    It seems like this should be possible.
    Message was edited by: RuthlessVengeance
    Message was edited by: RuthlessVengeance

    Select the music play list you want to listen to and start it playing. Go back to the home screen and start the app you want to use, music will stop. Press the home button two time quickly and it will bring up a simple control for controling the music. This works for me with all of the apps I have purchased including games. Just a note you can pull up the same music control if the iPod is a sleep and locked by pressing the button three times quickly.
    Mike

  • How can i read an COM port ???

    Hi,
    somebody knows how can i read an COM port from Forms 4.5 ?
    Thanks in advance.
    Patricio

    Hi Patricio
    have U got any solutions?? Im also trying to send message to display panel from forms 5.
    If You got any please let me know itll help me a lot
    Thanx
    Suraj

  • How can i us the parallel port of the printer to control a frequenz-generator?

    Hello all !
    I like to  control with LabVIEW 8 student-version, the Frequenz-generator gadget . For this challenge i like to us the parallel port of the printer. I need for data flow only 2 cable. The frequenz-generator gadget need two signal : Low and High.How  can i  us the parallel port of the printer to control a frequenz-generator gadget? I have us  the VIs-Visa  (Visa-Serial, write, Close ), but i dont no what command i have to write on the Visa-Write so that the Signal can be in the low or high position.
    Thanks

    Hi Jeanjac,
    first, look here:
    http://en.wikipedia.org/wiki/Parallel_port
    to get the port numbering. also, be sure not to leave pin unconected, sometimes you might get an error message otherwise (i remember pin11 has to be always connected or so for windows...)
    second, just run the test panel in MAX and write something to your device to check if it works.
    then in LV, you have to decide to which pin is connected your instrument. in any case you have to address all 8 output pins together! this is a parallel...
    if you prefere to use only one pin, then you can use the serial port, with just pin 2 and 3 connected. it would work easier for you, since you address only one bit.
    Gabriel
    ... And here's where I keep assorted lengths of wires...

  • How can you listen to music without headphones?

    How can you listen to music without headphones?

    - Try cleaning out/blowing out the headphone jack. Try inserting/removing the plug a dozen times or so.
    Try the following to rule out a software problem
    - Reset the iPod. Nothing will be lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup
    - Restore to factory settings/new iPod.
    - Make an appointment at the Genius Bar of an Apple store. Seems you have a bad headphone jack.
    Apple Retail Store - Genius Bar
    Apple will exchange your iPod for a refurbished one for this price. They do not fix yours.
    Apple - iPod Repair price
    A third-party place like the following will replace the jack for less. Google for more.
    iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens
    Replace the jack yourself
    iPod Touch Repair – iFixit

  • How can i install the air port utility on macbook air?

    How can i install the air port utility on macbook air

    Instructions and setup guide are here:
    http://manuals.info.apple.com/en_US/AirPort_Express_Setup_Guide.pdf

  • How can I listen to a sound file on Internet?

    How can I listen to a sound file? On Internet

    You need to download other browsers from the App Store. Use the App Store app And search for browsers you'll find a bunch of them. Download one that will do what you want. Once it's downloaded tap on the app icon to start the app.

Maybe you are looking for