Hi
I have to write a Client/Server application where initially client connects to a multi threaded server and exchanges requests and after server receives data it processes and send a reply. Server also performs other activity like connecting to client back and
exchange some data. Here i expect client to behave like a server so that it will run on another port or same port(im not sure about this) and accepts the server connection & request and reply back with some data.
In order to proceed I have just written a simple client/server(not multithreaded server) program that performs above activity.
But i get exception on server while it tried connected to client but gave connection refused.
I am running my client/server both programs in same pc.
Here is the code:
Server Program:
Client Program:
And following is the output in client & server respectivly:
##Client output:
Connecting to server...
Connected
Now sending data to server....
data sent to server
Listening on 4000 port
##Server output:
Server listening...3000 port
Client 192.168.200.227
Reading client data...
Data from Client########: Hello from Client
Now connecting to Client on 4000 port
Exception in
thread "main" java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at ServSocket.main(ServSocket.java:29)
Please help me
I tried googling for info but could not find any docs!!
regards