Article View: borland.public.jbuilder.java.api
Article #1786Quick question about sockets.
From: Alex Colic
Date: Thu, 06 Sep 2001 20:01
Date: Thu, 06 Sep 2001 20:01
31 lines
1736 bytes
1736 bytes
Hi, I have a couple of apps that listen on a socket for cmds. Eg. Start,
Stop.
I have created a class that has a thread that listens on the socket for
msgs. So far this has worked for me but when I have more than one app
installed on the same machine I get net bind exceptions that the port is
already taken.
Any suggestions are appreciated.
A snippet of my class is as follows:
public void run()
{
Socket inSocket;
while(shouldRun)
{
try
{
socket=new ServerSocket(port);
inSocket=socket.accept();
DataInputStream data=new DataInputStream(inSocket.getInputStream());
while(true)
{
String theLine=data.readLine();
if(theLine==null) break;
fireNewCmd(new newCmdEvent(this,theLine.trim()));
}
data.close();
socket.close();
}
Technical Details
Message-ID:
<3b97d61e_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,75eb349919d2da57,start X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2001-09-06 13:13:23 PST From: "Alex Colic" <alex.colic@pop-ware.com> Newsgroups: borland.public.jbuilder.java.api Subject: Quick question about sockets. Date: Thu, 6 Sep 2001 16:01:30 -0400 Lines: 33 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: 24.150.29.218 Message-ID: <3b97d61e_1@dnews> X-Trace: dnews 999806494 24.150.29.218 (6 Sep 2001 13:01:34 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews