package Z0929;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
public class MessageIO {
private static Socket c;
private InputStream in;
private OutputStream out;
static{
try {
c=new Socket("192.168.2.168",9999);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void SendMessage(String message){
try {
out=c.getOutputStream();
out.write(message.getBytes());
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
public String ReceriveMessag(){
String str="";
try {
in=c.getInputStream();
byte[] b=new byte[1024];
int i=in.read(b);
str=new String(b,0,i);
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public void close() {
try {
if (c != null) {
c.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}