您好,我在 golang 中创建了一个 Web 服务器,我已将其编译为 JAR/AAR 库,并将该库链接到我的项目,我能够启动 Web 服务器但无法通过我的主机(macos ) 我可以在我的控制台中看到:
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
但是当我尝试使用邮递员从我的主机设备查询这个网络服务器时,我得到了:
POST http://127.0.0.1:1313/api/v1/start_price_service
Error: connect ECONNREFUSED 127.0.0.1:1313
我的 android 清单看起来像:
<?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>
戈朗代码:
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)))
}
使用相同代码在 ios 上运行良好,但在这里我无法查询我的 http 服务器:/
我想澄清一下,我想从hostmachine (MacOS)
toemulator (Pixel XL API 30)
而不是相反的方式访问,我相信需要 10.0.2.2 端口