how can i get clients ip address on UDP server in golang?

Amir Mahmoudi :

I run a udp server successfully on go

func main() {
    service := "0.0.0.0:27014"
    udpAddr, err := net.ResolveUDPAddr("udp4", service)
    checkError(err)
    conn, err := net.ListenUDP("udp", udpAddr)
    checkError(err)
    for {
        handleClient(conn)
    }
}

But i Wanted to know how can i find out who(remote ip address, Client ip address) send request to my server

Didier Spezia :

In connected mode, you can use the LocalAddr() and RemoteAddr() methods of the connection object.

In disconnected (i.e. classical) mode, you get the address information with the datagram itself using one of the following methods:

func (c *UDPConn) ReadFrom(b []byte) (int, Addr, error)
ReadFrom implements the PacketConn ReadFrom method.

func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err error)
ReadFromUDP reads a UDP packet from c, copying the payload into b. It returns the number of bytes copied into b and the return address that was on the packet.

func (c *UDPConn) ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *UDPAddr, err error)
ReadMsgUDP reads a packet from c, copying the payload into b and the associated out-of-band data into oob. It returns the number of bytes copied into b, the number of bytes copied into oob, the flags that were set on the packet and the source address of the packet.

The address information is part of the return values in the signature of these methods.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Can't get 2 clients to listen to one UDP server

分類Dev

Get public IP in Golang

分類Dev

How to connect to elasticsearch server using rest client with IP address

分類Dev

How to get client IP address in Laravel 5+

分類Dev

How can I stop the timer permanently based on the user IP address?

分類Dev

How to bind http server with express object to a specific ip address?

分類Dev

How can I access a docker container via ip address

分類Dev

How do I send a UDP datagram with source address 0.0.0.0 in Rust?

分類Dev

how to get container host machine ip address and container name in EKS

分類Dev

How can I find an IP address in a long string with REGEX

分類Dev

How to get IP address from controller's hosts file in Ansible?

分類Dev

How to reserve IP Address in DHCP Server

分類Dev

Can we get IP address and/or machine of client accessing a particular website?

分類Dev

How can I send message to clients every x seconds when running a tornado server?

分類Dev

How can i hide the address bar of FCKeditor when the browse server button is pressed

分類Dev

Need to fill in IP address of the Server in my Clients Connection EditText

分類Dev

Can I get my IP address in a chrome app without using an external service?

分類Dev

How to point domain and subdomain to dedicated server using IP address?

分類Dev

How can I use SSH to tunnel Minecraft clients to my MineOS server?

分類Dev

why can't I ping Google with a static IP address?

分類Dev

why can I not managing to block an IP address in windows 7 firewall?

分類Dev

Recover a net device, I don't know IP-address, how to get arp?

分類Dev

From an IP how can I get a DNS entry?

分類Dev

How can I resolve an IP address to a hostname in Arch Linux?

分類Dev

How can I get autologin at startup working on Ubuntu Server 16.04.1?

分類Dev

How can AP work without having IP address assigned?

分類Dev

How to block clients by IP address from accessing certain URLs on my web server?

分類Dev

How can I get DNS IP Resolution for an Internet Domain Name pointing to a locally-hosted Web Server from within a LAN (across multiple subnets)?

分類Dev

How to run an SSH server without a static IP address

Related 関連記事

  1. 1

    Can't get 2 clients to listen to one UDP server

  2. 2

    Get public IP in Golang

  3. 3

    How to connect to elasticsearch server using rest client with IP address

  4. 4

    How to get client IP address in Laravel 5+

  5. 5

    How can I stop the timer permanently based on the user IP address?

  6. 6

    How to bind http server with express object to a specific ip address?

  7. 7

    How can I access a docker container via ip address

  8. 8

    How do I send a UDP datagram with source address 0.0.0.0 in Rust?

  9. 9

    how to get container host machine ip address and container name in EKS

  10. 10

    How can I find an IP address in a long string with REGEX

  11. 11

    How to get IP address from controller's hosts file in Ansible?

  12. 12

    How to reserve IP Address in DHCP Server

  13. 13

    Can we get IP address and/or machine of client accessing a particular website?

  14. 14

    How can I send message to clients every x seconds when running a tornado server?

  15. 15

    How can i hide the address bar of FCKeditor when the browse server button is pressed

  16. 16

    Need to fill in IP address of the Server in my Clients Connection EditText

  17. 17

    Can I get my IP address in a chrome app without using an external service?

  18. 18

    How to point domain and subdomain to dedicated server using IP address?

  19. 19

    How can I use SSH to tunnel Minecraft clients to my MineOS server?

  20. 20

    why can't I ping Google with a static IP address?

  21. 21

    why can I not managing to block an IP address in windows 7 firewall?

  22. 22

    Recover a net device, I don't know IP-address, how to get arp?

  23. 23

    From an IP how can I get a DNS entry?

  24. 24

    How can I resolve an IP address to a hostname in Arch Linux?

  25. 25

    How can I get autologin at startup working on Ubuntu Server 16.04.1?

  26. 26

    How can AP work without having IP address assigned?

  27. 27

    How to block clients by IP address from accessing certain URLs on my web server?

  28. 28

    How can I get DNS IP Resolution for an Internet Domain Name pointing to a locally-hosted Web Server from within a LAN (across multiple subnets)?

  29. 29

    How to run an SSH server without a static IP address

ホットタグ

アーカイブ