What do you actually want to achieve? What your code does is it tries to connect to a server located at 192.168.1.104:4000
. Is this the address of a server that sends the messages (because this looks like a client-side code)? If I run fake server locally:
$ nc -l 4000
...and change socket address to localhost:4000
, it will work and try to read something from nc
-created server.
ServerSocket
and listen on it:ServerSocket serverSocket = new ServerSocket(4000);
Socket socket = serverSocket.accept();
The second line will block until some other piece of software connects to your machine on port 4000. Then you can read from the returned socket. Look at this tutorial, this is actually a very broad topic (threading, protocols...)