Kamal Chopra

Greenhorn
+ Follow
since Jul 30, 2013
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kamal Chopra

That's not something the server code has control over - you need to run the code on whatever machine has that IP.



i know...its for assumption purpose dude


Hi all,,
I need to implement a TCP Server which should listen on port 1234 and should have ip=192.168.1.1,,,,
It should be able to accept connections of same subnets clients i.e.
192.168.1.2-254;;;
When it gets desired client should say to him Hello otherwise others should be welcomed "Good Bye"..
Any suggestions ??

Ulf Dittmer wrote:Your server's main method doesn't do anything. Somehow you deleted the line where it actually starts the server.



Will You Please mention/rectify for me the Particular Statement(s)?

Kamal Chopra wrote:

Ulf Dittmer wrote:Have you gotten this client/server pair to work? If not, that's what I recommend you start with.


Well, i did implement the single client/server interaction but am implementing it using two clients is my first experience...Any guidance will be appreciated.
Kamal



here is my server part:



Client:


Output:
Blank(nothing).
Whats wrong here???

Ulf Dittmer wrote:Have you gotten this client/server pair to work? If not, that's what I recommend you start with.


Well, i did implement the single client/server interaction but am implementing it using two clients is my first experience...Any guidance will be appreciated.
Kamal
Hi Coders!!!
I am connecting multiple servers (two) to a single server using UDP .
Server:


Client1:

Client2:

I am specifying same port numbers and other arguments vary except host address but at the end of the day no output appears ...

Bear Bibeault wrote:"Jeedi Jed", please check your private messages for an important administrative matter. Thanks.



I did responded..Thanks for intimation here..A novice user of this forum .Hope will soon be used to comply with the site regulations.
Thanks

Richard Tookey wrote:Your code works for me but I have taken it as a starting point and removed the redundant parts, changed the server class name, tried to make sure it binds to the correct interface ( localhost ), picks up the correct library classes and made the server loop forever accepting connections.. The exception handling is at best rudimentary but it works for me on both Linux and Windows 7 .





If this does not work on your system then I have to assume you have a network configuration problem.



It worked for me now... Thanks !! Tookey

SERVER PART:

CLIENT PART:

one thing more the methods such as InputStream getInputStream() & close() in server code are auto-generated methods ..

Richard Tookey wrote:

Jeedi Jed wrote:
For running Server part it returns:
Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind




As the exception indicates and has already been said by others, port 1254 is already being used by another process! Use a different port! Choose a port above 1023 since 0-1023 are reserved for 'well known' services. Until you stop getting that server exception there is no point in running your client.


Note - the NullPointerException from your client adds additional evidence that port 1254 is already in use since it means your client is connecting with it but not able to read the string.



Well,,, I am running both as different programs from the same project name and first i ran server it didnt return any error but now when i ran client it returned
Exception in thread "main" java.lang.NullPointerException
at java.io.DataInputStream.readUnsignedShort(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at Client.main(Client.java:12)

Client.java.12 points to String st = new String (dis.readUTF());
which means something like unable to read the string is going on......???

Richard Tookey wrote:

Jeedi Jed wrote:

Richard Tookey wrote:
I dont know how to make a connection b/w these two programs on the same machine....also i want to remove this exception it comes again and again



Start the server running in one command window. Run the client in a second command window. Worry about the exception when you have the client-server pair basically working.


But when i ran the client part it returned an error pointint to:

also returning NullPointerException
For running Server part it returns:
Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(Unkno wn Source)
at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at Socket.main(Socket.java:13)



Its driving me mad now as i am too slow now because of this bug!!!

Richard Tookey wrote:

Jeedi Jed wrote:Sorry to say THE count of VIEWS is increasing minutes to minutes but no suggestion/guidance



Maybe nobody is responding because, like me, when they test your code it works with no exception thrown.

P.S. It is not the cause of your problem but you just need


I dont know how to make a connection b/w these two programs on the same machine....also i want to remove this exception it comes again and again
Sorry to say THE count of VIEWS is increasing minutes to minutes but no suggestion/guidance as i am stuck and unable to proceed on....Please do guide me
I have just changed the port to 9999 and the rest of the code same....It was not compiling succesfully nor now....Also it is returning an error for the s1.close() and dis.readUTF() and it states an errors now when just running the client code:
Exception in thread "main" java.lang.NullPointerException
at java.io.DataInputStream.readUnsignedShort(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at Client.main(Client.java:11)