从客户端向服务器发送字符串的正确方法是什么?
try
{
ToServer.writeUTF(_textfield.getText());
//Try to send the strings in textarea (_textarea = new JTextArea(20,80) )
}
catch(IOException e)
{
e.printStackTrace();
}
我使用writeUTF和来自服务器的readUTF从客户端发送了字符串..
但它似乎不起作用。
答案 0 :(得分:0)
我使用标准Java套接字已经有一段时间但我相信你创建了一个新的outputStream,将其设置为套接字的输出流,创建一个新的PrintWriter并将其设置为写入OutputStream。
OutputStream outstream = new OutputStream(socket.getOutputStream());
PrintWriter out = new PrintWriter(outstream);
out.write("Hello Server!");