Description
I build a gin web server, some simple api just like this:
I can visit this api in PC http://192.168.1.5:2998/ping
But I can not visit this addr by my phone http://192.168.1.5:2998/ping
at the same time, i can visit the python web server http://192.168.1.5:3998/ping
why gin not allow the phone access the web api
how can i fixed the problem ? thanks very much.
How to reproduce
``` package main
import ( "net/http"
"github.com/gin-gonic/gin"
)
func main() { r := gin.Default() r.GET("/ping", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "message": "pong", }) }) r.Run("0.0.0.0:2998") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") }
Environment
- go version: 1.19
- gin version (or commit ref): last 1.7.7
- operating system: win /linux
Comment From: sdlyingyong
I tried to reproduce in the following environment, and as a result, the mobile phone can access the api. Try to open the debug mode of gin to see if the request has reached the api. Or try changing the port and try again.
#this is pc access
[GIN] 2022/11/01 - 16:28:29 | 200 | 0s | 192.168.2.9 | GET "/ping"
#this is phone access
[GIN] 2022/11/01 - 16:27:54 | 200 | 445µs | 192.168.2.64 | GET "/ping"
Environment
- go version: 1.19.2
- gin version (or commit ref): 1.8.1
- operating system: win
Comment From: XFrankly
hi, thanks very much, i try that again, same problem this tcp port :2999. its work normal with python web application, but its not ok for GIN web application. i had try different port
yes, i a,m sure its work in gin debug mode: this is gin web application not work**** [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production
this is tcp package i had capture in my network
345 148.852517 192.168.1.7 192.168.1.4 TCP 74 [TCP Retransmission] 51848 → 2999 [SYN] Seq=0 Win=65535 Len=0 MSS=1460 SACK_PERM=1 TSval=2276347578 TSecr=0 WS=256
Packet 2 from
- 203
- 64.944445
- 192.168.1.7
- 192.168.1.4
- TCP
- 74
- [TCP Retransmission] 51816 → 2999 [SYN] Seq=0 Win=65535 Len=0 MSS=1460 SACK_PERM=1 TSval=2276263678 TSecr=0 WS=256
- Frame 207: 74 bytes on wire (592 bits),
Internet Protocol Version 4, Src: 192.168.1.7, Dst: 192.168.1.4 0100 .... = Version: 4 .... 0101 = Header Length: 20 bytes (5) Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT) 0000 00.. = Differentiated Services Codepoint: Default (0) .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0) Total Length: 60 Identification: 0xd948 (55624) Flags: 0x40, Don't fragment 0... .... = Reserved bit: Not set .1.. .... = Don't fragment: Set ..0. .... = More fragments: Not set Fragment Offset: 0 Time to Live: 64 Protocol: TCP (6) Header Checksum: 0xdde7 [validation disabled] [Header checksum status: Unverified] Source Address: 192.168.1.7 Destination Address: 192.168.1.4 Transmission Control Protocol, Src Port: 51816, Dst Port: 2999, Seq: 0, Len: 0
this is my other web application work normal: Frame 3151: 74 bytes on wire (592 bits), 74 bytes captured (592 bits) on interface \ id 0
Internet Protocol Version 4, Src: 192.168.1.7, Dst: 192.168.1.4 0100 .... = Version: 4 .... 0101 = Header Length: 20 bytes (5) Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT) 0000 00.. = Differentiated Services Codepoint: Default (0) .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0) Total Length: 60 Identification: 0x6a5c (27228) Flags: 0x40, Don't fragment 0... .... = Reserved bit: Not set .1.. .... = Don't fragment: Set ..0. .... = More fragments: Not set Fragment Offset: 0 Time to Live: 64 Protocol: TCP (6) Header Checksum: 0x4cd4 [validation disabled] [Header checksum status: Unverified] Source Address: 192.168.1.7 Destination Address: 192.168.1.4 Transmission Control Protocol, Src Port: 34244, Dst Port: 2997, Seq: 0, Len: 0
Comment From: XFrankly
so , i am sure GIN web application is running on DEBUG mode on tcp port :2999 But, this service do not allow TCP connation , when my phone ask a TCP SYN. SO, there do not have any GIN debug log. Any idea for me?
Comment From: XFrankly
so , i am sure GIN web application is running on DEBUG mode on tcp port :2999 But, this service do not allow TCP connation , when my phone ask a TCP SYN. SO, there do not have any GIN debug log. Any idea for me?
Ok. I fixed the problem, because the fireware system of the OS is not allow web application communication by default.
Comment From: sdlyingyong
congratulate