public class ClientApp
{
public static void Main (String args[])
{
Try
{
Create communications and connect to the host rock
Socket csocket=new socket ("192.168.100.188", 8018);
Open the input/output stream for this socket
OutputStream Os=csocket.getoutputstream ();
DataInputStream is=new DataInputStream (Csocket.getinputstream ());
int C;
Boolean flag=true;
String Responseline;
while (flag)
{
Accept characters from standard input output and write as System
while ((C=system.in.read ())!=-1)
{
Os.write ((byte) c);
if (c== ' \ n ')
{
Os.flush ();
Block the program until the reply is received and display them on the standard output
Responseline=is.readline ();
SYSTEM.OUT.PRINTLN ("message is:" +responseline);
}
}
}
Os.close ();
Is.close ();
Csocket.close ();
while (flag)
{
Clientsocket=ssocket.accept ();
DataInputStream is= New DataInputStream (New Bufferedinputstream (Clientsocket.getinputstream ()));
OutputStream Os=clientsocket.getoutputstream ();
while ((Inputline=is.readline ())!=null)
{
The server program terminates when the client enters the stop!
if (Inputline.equals ("Stop"))
{
Flag=false;
Break
}
Else
{
System.out.println (Inputline);
while ((C=system.in.read ())!=-1)
{
Os.write ((byte) c);
if (c== ' \ n ')
{
Os.flush (); Sending information to the client
Break
}
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.