0

I have a server running that runs on TCP/IP. It reads strings and responds with strings. I just wondered if I can just connect via Flash to my server and get some answers from it. My second idea was:

var socket: Socket = new Socket("192.168.0.100", 4847);

socket.writeObject("hello");
var answer: String = socket.readObject();

trace(answer);

Connection is established successfully. But I'm not sure how I send and receive strings now.


Update:

  • socket.writeUTFBytes("hello\r\n"); seems to work for sending
  • how to read ? socket.readUTF() ?
    • I don't know how long the answer might be, it can be short or very long
  • how about end of line ? It is important for my server since that's how messages are separated. Do I have to send eol via "\r\n" ?
  • Update 2: This seems to work well
4

1 回答 1

1

这取决于您的服务器如何处理请求和响应。对于发送和接收字符串,请使用 readUTFBytes 和 writeUTFBytes。

如果您想使用函数 writeObject 和 readObject,您的服务器必须知道如何处理 AMF 序列化。您可以在此维基百科页面http://en.wikipedia.org/wiki/Action_Message_Format上找到不同语言的库,并在服务器上实现 AMF。如果您正在从事一个更大的项目,我个人会建议您这样做。

于 2013-11-05T10:19:32.680 回答