Re: Multiple Client Sockets, Single java program, connect to server socket, possible?



On 8 Dec 2006 02:55:02 -0800, dynaheir@xxxxxxxxxxx wrote:
I have a strange problem. I started work on software expecting that it
was possible to create many client sockets in a single instance of a
java program that connect to a single server where ever that maybe.

Your code is unnecessarily complex for the task, and somewhat
difficult to follow. Here are some suggestions:

- you are doing too much work in your constructors. Use the
constructor to *initialise* the object. Invoke methods to *do*
something with the object.

- drop all use of setReuseAddress(), it serves no purpose at all here.

- the normal way to delay execution is with Thread.sleep(). Calling
notify() followed by wait() does not do what you seem to think, but
you shouldn't be polling here anyway.

- I cannot see need for any synchronization (notify(), wait(), or
yield()) in this code, and your use of these methods seems to
indicate that you do not really understand what they do, or how to
fix your program.

- there is no need to use available() before reading, in fact it will
only cause you grief. You can replace your read loop with something
more like this:

try {
while (true) {
str = dis.readUTF();
System.out.println(str);
}
catch (IOException e) {
e.printStackTrace();
System.out.println("dead");
}

The above loop could be made even simpler if you used a
BufferedReader instead of a DataInputStream, since reaching EOF
isn't really an exceptional event.

- your server fails to close the client socket after reaching EOF.
Don't rely on GC for this, you *will* run out of descriptors.

- when a client calls connect(), it will succeed even though the
server is not waiting in accept(), and it will be able to send a
limited amount of data. However unless the server invokes accept(),
there is nobody receiving the data, and the client will eventually
block.

- after accepting a connection, do not simply invoke the reqRec
constructor (most of which should be in a method anyway). After
calling accept() the server must create a thread to handle each new
client, so that it can go back to accept() as quickly as possible.

/gordon

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
.



Relevant Pages

  • Re: What doesnt lend itself to OO?
    ... >> proxy and instructs the server to constuct the real object. ... rather than client code. ... If 'clock' is instantiated in the server, ... > for the server interface at the OOA level. ...
    (comp.object)
  • This is going straight to the pool room
    ... or not the client has privilege to do what they're trying to do, ... The server environment is this: ... 3GL User action Routines that Tier3 will execute on your behalf during the ... Routine Name: USER_INIT ...
    (comp.os.vms)
  • [Full-Disclosure] R: Full-Disclosure Digest, Vol 3, Issue 42
    ... Full-Disclosure Digest, Vol 3, Issue 42 ... SD Server 4.0.70 Directory Traversal Bug ... Arkeia Network Backup Client Remote Access ...
    (Full-Disclosure)
  • Re: What doesnt lend itself to OO?
    ... > rather than client code. ... no way to do that without also touching the object with clock semantics ... will not encapsulate both clock semantics and network semantics. ... The server can do whatever it wants ...
    (comp.object)
  • RE: Fax monitor incoming + outgoing calls?
    ... problem between the client computer and the SBS server. ... Client is using the internal IP address of the SBS server as the ... To the folder redirection GPO issue: ...
    (microsoft.public.windows.server.sbs)