Originally Posted by
KingJohnno
...
I am having problems with this code...
...I am curious to know If I need two copies of Eclipse open simultaneously, or If (like i have been doing) having one window open and running the two different classes together....
I think the code is OK.
.
Here's what I would do to test it: (In fact, here's what I did on my Centos 6.3 Linux system.)
Forget about Eclipse for now. Here's the drill:
- Create a working directory for this project. Anywhere you want. (On my Linux system, I have a Java test directory under my home directory.) Make a brand new directory with nothing else in it.
- Open a command window and navigate to the project working directory that you just created.
- Open an editing session with your favorite text editor (gvim, right?). Paste in the server stuff and save as Server.java. Now, I changed the socket line to the following so that I can make absolutely, positively, unequivocally sure that everything that happens on my machine stays on my machine (just like Las Vegas) and won't go out over my LAN or WAN or the Internet or anywhere else.
At least that's my fond hope when I am developing new network applications---don't get blacklisted by my ISP for spewing garbage. They really, really (really) don't like that. They're funny that way.
Socket skt = new Socket("localhost", 2009); // Could use "127.0.0.1" but I like "localhost" for certain reasons.
- Open another editing session and paste in the client stuff and save as Client.java (You will probably find that you need to add import staements for java.io.* stuff and java.net.* stuff at the top of Client.java, right?)
- Execute javac Server.java and javac Client.java from the command line. Make any corrections needed to get a good, clean compile from both.
- Open another terminal window in your project working directory.
- Open Wireshark and set it to capture port "lo" or whatever it is that your system uses to identify 127.0.0.1 as localhost. Now we are ready for action.
- In one of the terminal windows, execute java Server
You should see some stuff in the Wireshark capture window.
- In the other terminal window, execute java Client You should see some more activity in Wireshark, and equally importantly, you should see your expected messages in the Server command window and the Client command window.
In the Server window:
Server has connected!
Sending string: 'Toobie ornaught toobie'
Then the Server application closes and you are back at a command prompt in the server window.
In the Client window:
'Toobie ornaught toobie
'
Then the client application closes and you are back at the command prompt in the client window.
- In the client window execute java Client again. Now what happens?
Cheers!
Z