Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Ethmaster

Members
  • Content Count

    4
  • Joined

  • Last visited

Posts posted by Ethmaster

  1. Hey guys,

     

    I'm working on building 2 programs;

    1. Allows a user to bind a custom address to the local machine, open a port, listen to it for TCP traffic, await for a TCP event, pulls some information from the event (remote addr, port, etc.), ask if you'd like to send a reply, and if yes, send it then going back to listening, if no, go back to listening.

    2. Asks you for the address you'd like to connect with, the port on the destination machine, and then the message you'd like to send, and then awaits a reply from the remote host. One it receives it, it allows you to then reply and alternate between listening and sending to allow for a conversation.

     

    I can code all of it, I was just wondering if there was some documentation somewhere of the Network API, and what events/information comes in what orders, so I can properly grab what information I want for this to work. 'man network' gives me a list of commands, parameters, and some description, but isn't exactly clear on what events, and in what order the information comes in, as I need to save the channel, remoteaddr, and some other information from the events in order to get this working. 

     

    Thanks for any and all help, guys!

    EDIT: I'm using the network floppy, and the commands listed there in order to get this to work, so network.tcp.open, network.tcp.send, network.tcp.listen, etc.

  2. I have been able to get the full addresses using the components program and writing it down, however, my trouble was with finding the abbreviated address that's used. I was hoping to let the user add in those, then the message program would be able to use the abbreviated address of the destination modem to send it there, without having to give everyone the full address, to make things a bit easier. Any ideas on where I can find the abbreviated address?

  3. Hello guys,

     

    I saw on the wiki that we could abbreviate addresses, and I was wondering how that was done.

     

    I just finished writing a simple program that uses wireless network cards and access points to fire off text messages, which the other computer receives when it uses the listening program I also built, however it requires me to type in the full address of the modem of the receiving computer, and I was wondering if there was a way to shorten that address, or give it a second address that the modem would respond to, to make things a little easier.

     

    I saw on the network floppy there's ifconfig, and that has a bind command to it, but would that make the modem respond to that new, given address if sent over the wireless network?

    Here's the code to the message program, if it helps at all. Thanks!

    local component = require("component")
    local computer = require("computer")
     
    if not component.isAvailable("modem") then
     io.stderr:write("A modem is required to use this program, preferably from a wireless network card.")
     return
    end
     
    if not component.isAvailable("access_point") then
     io.stderr:write("An access point is required to use this program. It allows for great wireless transmissions")
     return
    end
     
    local ap = component.access_point
    local m = component.modem
     
    if not m.isWireless() then
     print("Sorry, this program only really does anything useful if you have a wireless network card installed")
     return
    end
     
    print("Please type in the address of your recipient: ")
    local addr = io.read()
     
    print("Please type in the port you wish to send this message along to: ")
    local strport = io.read()
     
    print("Now, please type the message you wish to transmit")
    local message = io.read()
     
    print("Finally, type the distance the message must cross (always be liberal when guessing distance): ")
    local rangestr = io.read()
     
    print("\n\nInformation added in, configuring message parameters...")
    local portnum = tonumber(strport)
    local rangenum = tonumber(rangestr)
     
    print("Configured. Now setting ranges...")
    m.setStrength(rangenum)
    ap.setStrength(rangenum)
     
    print("Ranges configured. Set to: "..rangenum)
    print("Inputs compiled. Finalizing transmission...")
    m.open(portnum)
     
    if m.isOpen(portnum) then
     print("Data port is opened, proceeding with message transmission...")
     if  m.send(addr, portnum, message) then
      print("Message sent! Please ensure receipt of message!")
      return
     else
      print("Message not sent! Communications failure!")
      return
     end
    else
     print("Communications failure! Unknown reason!")
    end
    
  4. Hey guys!

    I'm trying to play around with basic network messages and the like (i.e. tell it the port to broadcast on, the message, and the strength desired), and so I created a counterpart listening program to open ports 1-20 and report whether they're functional or non-functional, and then it moves on to waiting for the message. Issue is, when I open the ports up, only ports 20, 10, and 1 actually report being functional, the others all seem to be closed, any ideas?

     

    Broadcast program:

    local component = require("component")
    local computer = require("computer")
     
    if not component.isAvailable("modem") then
     io.stderr:write("A modem is required to use this program, preferably from a wireless network card.")
     return
    end
    if not component.isAvailable("access_point") then
     io.stderr:write("An access point is required to use this program. It allows for great wireless transmissions")
     return
    end
     
    local ap = component.access_point
    local m = component.modem
     
    if not m.isWireless() then
     print("Sorry, this program only really does anything useful if you have a wireless network card installed")
     return
    end
     
    print("Please input on which port you would like to broadcast (number): ")
    local portstr = io.read()
    print("Now, please input the message you would like to send (string): ")
    local msg = io.read()
    print("Lastly, how far would you like this broadcast to go? (number): ")
    local strrange = io.read()
     
    print("Reading input, preparing message...")
    local portnum = tonumber(portstr)
    print("Message prepared, setting desired broadcast range...")
    local range = tonumber(strrange)
    m.setStrength(range)
    ap.setStrength(range)
    print("Range set to: " .. range)
     
    print("Input read, checking port status...")
     
    if m.isOpen(portnum) then
     print("Port is opened, proceeding with broadcast...")
     if m.broadcast(portnum, msg) then
      print("Message successfully sent!")
      return
     else
      print("Message not sent! Unknown reason!")
      return
     end
    else
     m.open(portnum)
     print("Port has been manually opened, proceeding with broadcast...")
     if m.broadcast(portnum, msg) then
      print("Message successfully sent!")
      return
     else
      print("Message not sent! Unknown reason!")
      return
     end
    end
    

    Listening program:

    local component = require("component")
    local event = require("event")
     
    if not component.isAvailable("access_point") then
     print("Access Point should be available to assist this program...")
     return
    end
     
    if not component.isAvailable("modem") then
     print("A modem (from a network/wireless network) card is necessary to use this program. Thanks!")
     return
    end
    local m = component.modem
    local ap = component.access_point
     
    if not m.isWireless() then
     print("This modem should be from a wireless network card. Please replace the network card with a wireless network card.")
     return
    end
     
    print("Please enter desired range for listening/relaying: ")
    local strrange = io.read()
    local range = tonumber(strrange)
     
    ap.setStrength(range)
    print("Listening/Relay range set to "..range)
    print("Opening ports for listening (1-20)...")
     
    local portnum = 20
     
    while portnum>0 do
     m.open(portnum)
     portnum = portnum - 1
    end
     
    print("Confirming ports are open...")
    local portscan = 20
     
    while portscan>0 do
     if m.isOpen(portscan) then
      print("Port: "..portscan.." is ready.")
     else
      print("Issue with port: "..portscan..". This port is not open.")
     end
     portscan = portscan - 1
    end
    print("Ports have been opened. Awaiting message...")
     
    local _, _, from, port, _, message = event.pull("modem_message")
    print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
    

    Thanks for any and all help, guys!

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.