Last week, during the prac 2 of CS IB, we were asked to program in Java to build a simple client/server system in which the server takes “commands” from the client and executes them. Due to the time restriction, we were only asked to implement the server, and use telnet to act as client to transact with server. You can have a look here for details.
1 2 3 4 5 |
ServerSocket server = new ServerSocket(6666); Socket s= server.accept(); // We now have a client on the end of the socket s BufferedReader in = new BufferedReader( new InputStreamReader( s.getInputStream())); PrintWriter out = new PrintWriter(s.getOutputStream()); |
It’s no more than the knowledge above. Maybe the simplest nextwork program in Java world.
The telnet on lab’s Mac just work well, but after I brought my program to home and run on my own computer, I met a really troublesome problem with the Microsoft’s telnet in Windows XP.
1. First, I started my server.
2. Then, I opened the console in XP. Typed in the telnet command: telnet localhost 6666 (6666 is my server port number).
3. Server side msg indicated that I successfully connected.
4. How about the client side?
The nice bug come out! When you are typing, you can’t see what you have typed. Why is that? The Google says: When you type your password, local echo is switched off so others cannot see what you are typing. Unfortunately, Telnet fails to switch it back on again, and fails to accept any further entries!
5. solution: press “Ctrl + ]”, then input “set localecho”, and hit return twice. You should now be able to see what you type.
6. The whole transaction of my Online Shop Server looks like this (You can check the detailed requirements):
- Create account
- List the products
- Add the corresponding products to shopping basket
- Commit the transaction
- Terminate the session
7. When use “QUIT” command, the connection is closed. But my server keep running.
8. Really solved the problem? Unfortunately, you will need to repeat step 5 each time when you enter console. That’s really noising. But I found a really sweet alternative program, called PuTTY.
blah, blah, blah just four steps
trying to use PuTTY as Telnet to connect my server…
9. Connected again.
10. Very pleasant interface.
If you have interests, test my code yourself.
强悍..专业..嘿嘿! 我对计算机语言是一窍不通..
nice~ work~ I also found the console problem in XP, but I just use the console to print one line TXT , then every thing was solved~, Still thank you for you good idea.
didn't catch ur idea what do u mean by just "use the console to print one line TXT"? are u working on the same prob?
hugo use the first line to cover the XP console BUG, and at the following lines everything seems fine hoho~~
but
here is also a problem
if u correct ur wrong typing command to a right one in console, did u find the print-out is still “not such command”?show me the codes tmr.
没想到发现了一个同样这么热爱编程的人…好像还同样是读CS1B的?
心里感觉特棒, 热血沸腾~哈哈~得加油了…
Hugo's idea is to print out something just after the connection was established, then the telnet prog will turn on the local echo automatically. Now I believe what Tony Levi had said – it's not a bug, but a feature
I tried to get ur code, but I am not a student of Adelaide, May you mail me your code? many thanks