client server communication problem through URLConnection

I

itpartha

Dear all
I am implementing a general purpose chat software using Core
Java. The client is an applet that uses HttpURLConnection to
communicate to the server. Currently the client periodically makes
request to the server though most of the time it has nothing to send,
and the server responds though sometime it has nothing to reply and
closes the connection. The identity of the clent as well as the message
to send is attached to the request header. But periodically hitting the
server makes the proxy slow responding to other users.
I tried to make it like that whenever the client has something
to send it requests the server, the server then verifies that whether
the incoming connection request is coming from a client that has a
previous connection active. If so then it first closes the first
connection, then process the new request data. Now on, the server uses
the new connection to send data to that client and keeps the connection
alive until the next request reaches. The will certainly require less
traffic.
But the problem is that while the server has a running
connection to a client, it blocks reading from other connections from
the client until the previous connection is closed, while without
reading from the new connection the server can't find the client's
identity and close the previous alive connection.
Somebody please help me to find the solution.
 
F

feradz

Hi, here I can not understand what exactly is your goal in your
clinet-server application but will try to give you an advice that may
work out.

Now, It would be better to server each client with a separate. When a
server sockets accepts a client connection, create a separate thread
that will deal with that particular client requests. So if there are 5
clients connected to the server simultaneously, there will be 5 threads
in the server app that will run simultaneously and serve each client.

There is a simple example for this on sun's site
http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html

I home that my answer was relevant to your problem.
Ferad Zyulkyarov
 
T

timjowers

I think the connection is identified by a four tuple.
(srcIP,srcPort,destIP,destPort)

You cannot have two connections with identical four tuples. The network
drivers of your OS require uniqueness o know to which app to route the
packet.

Perhaps your client, srcIP, is always using the same port, srcPort,
when it attempts to connect? Otherwise surely Java allows more than one
connection from a client. Write a simple test and let us know.

TimJowers
 
T

timjowers

Oh yeah, look at the HTTP/1.1 keepalive in URLConnection. It tells the
server to keep the connection open rather than close it. Maybe your way
would be to turn it off.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top