小编kAm*_*mol的帖子

通过TCP套接字将音频写入服务器

我正在尝试通过TCP套接字和服务器将实时麦克风录制传输到服务器,以将输入流写入文件.建立连接但是在一段时间后,我在客户端遇到连接拒绝错误.

服务器代码:

    public class auServer extends Thread{
    private static ServerSocket serverSocket;
    private static int port = 3333; 

    public void run()
    {

        System.out.println("init success");
       while(true)
       {

          try
          {
              serverSocket = new ServerSocket(port);
              serverSocket.setSoTimeout(10000);
              Socket clientSoc = serverSocket.accept();
             System.out.println("Waiting for client on port " +serverSocket.getLocalPort() + "...");
             System.out.println("Just connected to " + clientSoc.getRemoteSocketAddress());
             InputStream in = clientSoc.getInputStream();
             while(in!=null)
             {
                 writeToFile(in);
             }
             System.out.println("socket");

             clientSoc.close();
          }catch(SocketTimeoutException s)
          {
             System.out.println("Socket timed out!");
             break;
          }catch(IOException e)
          {
             e.printStackTrace();
                     System.out.println("some io");
             break;
          } catch (Exception e) { …
Run Code Online (Sandbox Code Playgroud)

java sockets android tcp stream

17
推荐指数
1
解决办法
1327
查看次数

为什么我得到getApplicationcontext()null?

我不确定它有什么不对!我在这里读到Intentservice本身就是它的子类Context.

public class GCMNotificationIntentService extends IntentService {
    private NotificationManager mNotificationManager;
    NotificationCompat.Builder builder;
    Context mainContext;
    WriteFile writeFile;

    public GCMNotificationIntentService() {
        super("GcmIntentService");
        mainContext = getApplicationContext();
        writeFile = new WriteFile(mainContext);
    }
    // My rest of the code
}
Run Code Online (Sandbox Code Playgroud)

但是我的价值是空的mainContext.任何建议都是最受欢迎的.

android push-notification android-notifications android-intentservice

4
推荐指数
1
解决办法
2836
查看次数