Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us |
Your current position : Homepage > Free Software > Technological exchanges >Application Programming


    

Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006


Socket Programming on the issue

Import java.net.*;
Import java.io.*;
Public class myserver
{
Public static void main (String args[])
   {
ServerSocket server;
Socket socket;
String s;
InputStream Is;
OutputStream Os;
PrintStream mi
Try
      {
Server = new ServerSocket (4321);
Server.accept = socket ();
System.out.println ( "server ok");
System.out.println ( "************************************************");
System.out.println ( "");
Is = socket.getInputStream ();
Os = socket.getOutputStream ();
PS = new PrintStream (Os);
DataInputStream in = new DataInputStream (System.in);
InputStreamReader isr = new InputStreamReader (Is);
BufferedReader br = new BufferedReader (isr);
BufferedReader br1 = new BufferedReader (new InputStreamReader (System.in));
While (true)
         {
System.out.println ( "");
System.out.println ( "please wait client 's message. . . ");
System.out.println ( "");
S = br.readLine ();
System.out.println ( "client said :" + s);
If (s.trim (). Equals ( "886"))
Break;
System.out.print ( "you say :");
Br1.readLine s = ();
PS.println (s);
If (s.trim (). Equals ( "886"))
Break;
         }
PS.close ();
Is.close ();
Os.close ();
Socket.close ();
) Catch (Exception e)
      {
System.out.println ( "Error :" + e);
      }
   }
}
Br1 = new BufferedReader process BufferedReader (new InputStreamReader (System.in));
As System.in is byte flow, which has become a br1's character is a character variable flow through PS.println (s); Character is not put into byte flow automatically exported. Like the time the data transmitted without
InputStreamReader isr = new InputStreamReader (Is);
Circulation should first byte characters into the corresponding flow during the operation. I do not know the correct understanding

Input InputStreamReader only completed the conversion and byte characters, you have to spend to complete output
OutputStreamReader.

First point above statement could client端 server端 procedures for Socket Communications
Secondly, I only found a java OutputStreamWriter could not find OutputStreamReader
Output also need to change? Server端 procedures as an example of how to change the country, I

......................
Br1.readLine s = ();
PS.println (s);
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4003rd may be varied during the procedure?

Halo one, of course, take outputStream only writer, and similarly, you will find a mixed inputstreamwriter I would henceforth with you.

I do not know if you want to achieve anything, only vague : inputstream agent of the input flow socket, the socket outputstream agent for the import flow (of course only on the importation flow reading, writing on the output flow).



 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com