1

Hello i created a web server in golang, i've compiled it to a JAR/AAR library and i've linked this library to my project, i'm able to start the web server but not communicate with hit through my hostmachine (macos) i can see in my console:

D/HostConnection: HostConnection::get() New Host Connection established 0xeae2bb30, tid 12502
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_sync_buffer_data GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_3_0 
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/EGL_emulation: eglCreateContext: 0xeae2bc10: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xeae2bc10: ver 3 0 (tinfo 0xeb1784f0) (first time)
I/GoLog: [32m2021-07-16 16:01:08    [INFO]: Launch MM2 Tools Server from android[39m
I/GoLog: [32m2021-07-16 16:01:08    [INFO]: memory store created[39m
I/GoLog: [32m2021-07-16 16:01:08    [INFO]: Middleware created[39m

But when i try to query this web server from my hostdevice with postman i got:

POST http://127.0.0.1:1313/api/v1/start_price_service
Error: connect ECONNREFUSED 127.0.0.1:1313

my android manifest looks like:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Golang code:

func LaunchServer(appName string) {
    if runtime.GOOS == "ios" {
        glg.Get().SetMode(glg.STD)
        glg.Info("Launch MM2 Tools Server from ios")
    }

    if runtime.GOOS == "android" {
        glg.Get().SetMode(glg.STD)
        glg.Info("Launch MM2 Tools Server from android")
    }

    gAppName = appName
    router := InitRooter()
    rate, err := limiter.NewRateFromFormatted("30-M")
    if err != nil {
        glg.Fatalf("error on limiter: %v", err)
        return
    }

    store := memory.NewStore()
    glg.Info("Memory store created")

    // Create a fasthttp middleware.
    middleware := mfasthttp.NewMiddleware(limiter.New(store, rate, limiter.WithTrustForwardHeader(true)))
    glg.Info("Middleware created")

    glg.Fatal(fasthttp.ListenAndServe(":"+fmt.Sprintf("%d", 1313), middleware.Handle(router.Handler)))
}

Works well on ios with the same code, but here i'm unable to query my http server :/

I want to clarify that i want to access from hostmachine (MacOS) to emulator (Pixel XL API 30) and not the opposite way which require 10.0.2.2 port i believe

roman Sztergbaum
  • 671
  • 1
  • 5
  • 11

0 Answers0