Actionscript套接字连接到java套接字。挂在readline上() [英] Actionscript socket connect to java socket. hanging on readline()

查看:95
本文介绍了Actionscript套接字连接到java套接字。挂在readline上()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,



我想通过套接字将一个字符串从actionscript发送到java。

这是我的java代码

Greetings,

I want to send a string from actionscript to java trough a socket.
this is my java code

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;


public class Main
{
  public static void main(String[] args){
    try{
      // 8080ポートを使ってサーバソケットを作成
      ServerSocket server = new ServerSocket(8080);
      
      System.out.println("1サーバソケット作ってflashの接続待ち");

      
      // Flashからの接続待ち
      Socket socket = server.accept();
      
      System.out.println("2接続成功しました");

      // 出力ストリームを作成
      BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

      
      System.out.println("3出力ストリーム作成しました");
      
      while (true){
        System.out.println("4最初のwhile文突入");
        String str = "";
        
        System.out.println("5これから読み込みます");
        // 一文字読み込む(Flashから転送されるまでここで止まる
        String c = in.readLine();
        
        System.out.println("6読み込みしました");

        // エラー(通信が切れた
        if(c == null){
          System.out.println("7通信が切れた");
          break;
        }

        // '.'が来るまで繰り返す
        while (c != "\0"){
          System.out.println("8最後のwhile");
          str += c;	// 文字列に結合する
          c = in.readLine();	// 次の1文字読み込む
        }

        // 送られてきたメッセージを表示
        System.out.println(str);
        
        }

      in.close();
      socket.close();
      server.close();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}



这是我的行动


and this is my actionscript

var socket = new XMLSocket();


// IP "localhost "のポート8080番に接続
socket.connect("localhost", 8080);
socket.send("A MESSAGE \r\n"  );





问题是java代码挂起在in.readline();

当我关闭flash程序时,java代码继续并进入以下if语句。



the problem is the java code hangs on in.readline();
when i close the flash program the java code continues and goes in to the following if statement.

if(c == null){
          System.out.println("7通信が切れた");
          break;
        }





我想要的是java代码读取我用actionscript发送的字符串然后打印字符串。



what i want is that the java code reads the string i send with actionscript and then prints the string.

推荐答案

答案你需要好好准备数据格式

当试图关闭一个套接字时,首先刷新流

我根本不喜欢日语
the answer's you need to good prepare you data-format
when try to close one socket ,flush the stream first
I don't like japanese at all


这篇关于Actionscript套接字连接到java套接字。挂在readline上()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆