FAQ
hi,
I have an assignment in my university, i need to listen to an ip:port and a
hardware will send a packet and the server needs to answer to the
hardware , but i dont know how to start.

I have seen some examples but only like an http server but dont know how to
read packets and response.



Listen to an IP:PORT

A hardware will send a data packet with this ifo:

76760D01012345678901234500018CDD0D0A

do something

The server will answer this:
767605010001D9DC0D0A


Please help me to create the code to listen and answer that data.
Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at Sep 2, 2015 at 1:47 pm

    On Wed, Sep 2, 2015 at 1:48 AM, wrote:
    I have an assignment in my university, i need to listen to an ip:port and a
    hardware will send a packet and the server needs to answer to the hardware
    , but i dont know how to start.

    I have seen some examples but only like an http server but dont know how to
    read packets and response.



    Listen to an IP:PORT

    A hardware will send a data packet with this ifo:

    76760D01012345678901234500018CDD0D0A

    do something

    The server will answer this:
    767605010001D9DC0D0A


    Please help me to create the code to listen and answer that data.
    This mailing list is not really here to help you do your homework.

    That said, look at the net package, starting with net.Listen.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Konstantin Khomoutov at Sep 2, 2015 at 2:08 pm

    On Wed, 2 Sep 2015 01:48:51 -0700 (PDT) ejalvarg@gmail.com wrote:

    I have an assignment in my university, i need to listen to an ip:port
    and a hardware will send a packet and the server needs to answer to
    the hardware , but i dont know how to start.

    I have seen some examples but only like an http server but dont know
    how to read packets and response.
    Well, I do understand that it's easy to find once you know the answer,
    but really you had to google for "golang+chat+server" -- because
    writing a simple chat server is the sort of "hello world" example for
    socket-based networking applications.

    So consider just googling for what I proposed [3] and study those
    examples whith appear to use TCP (no websockets and other web-y stuff).
    Among the results brought by that search query, [4] looks like a good
    example to start looking at. See below for why I mentioned TCP.
    Listen to an IP:PORT
    Hmm, you should elaborate (for yourself) on this point: you can't just
    "listen on IP:PORT" because IP has no concept of "a port" -- it only
    knows about addresses and is able to deliver packets between them.
    Ports are property of some higher-level protocols which use IP as their
    transport layer. TCP and UDP are the two most widely used examples of
    them. So you have to make sure what protocol above IP you're supposed
    to use before you start [*].
    A hardware will send a data packet with this ifo:

    76760D01012345678901234500018CDD0D0A

    do something

    The server will answer this:
    767605010001D9DC0D0A

    Please help me to create the code to listen and answer that data.
    Thanks in advance.
    Look at [1], in particular, its sections titled "Socket-level
    Programming" and "Data Serialization".

    Please also note that asking for help right away without showing any
    prior reseach performed by you is a bad behaviour which might turn off
    quite a lot of people technically able to help. When you have time,
    please consider reading [2] for more insight on this.

    [*] Well, in theory, it's possible to work with "raw IP networking",
         but I highly doubt you would be assigned a task like this in a
         University.

    1. https://jan.newmarch.name/go/
    2. http://whathaveyoutried.com
    3. https://www.google.com/search?q=chat+server+golang
    4. https://gist.github.com/drewolson/3950226

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Konstantin Khomoutov at Sep 2, 2015 at 3:20 pm
    On Wed, 2 Sep 2015 17:07:57 +0300 Konstantin Khomoutov wrote:
    [...]
    Listen to an IP:PORT
    Hmm, you should elaborate (for yourself) on this point: you can't just
    "listen on IP:PORT" because IP has no concept of "a port" -- it only
    knows about addresses and is able to deliver packets between them.
    Ports are property of some higher-level protocols which use IP as
    their transport layer. TCP and UDP are the two most widely used
    examples of them. So you have to make sure what protocol above IP
    you're supposed to use before you start [*].
    [...]

    Oh, I have completely missed the subject of this mail which clearly
    states you want TCP.

    OK, so any example googled via "golang+tcp+socket+example" will
    probably be suitable for studying. Using this query I've just found
    [1] which appears to be as minimal as practically possible why still
    being illustrative.

    Hope by now you've got the idea of how to get yourself going.

    1. https://systembash.com/a-simple-go-tcp-server-and-tcp-client/

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 2, '15 at 12:29p
activeSep 2, '15 at 3:20p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase