Página 1 de 1

TCP/IP Send

Publicado: 13 Sep 2019 01:44
por sendai
Hello everyone, i need help regarding sending data into remote host using TCP/IP or UDP
Our teacher created an application that can merely receive data using TCP/IP or UDP, now she want us to create a simple application in any language that we can send data to her application,

example: Her application is running in this IP: 192.168.10.10 Port 6524

so i think using AMS if its possible.

i found example_TCP_SERVER_MULTITHREADED i tried but the connection becomes lost after few minutes.
anyone can provide simple example apz for this? thank you so much.



Sendai

Re: TCP/IP Send

Publicado: 13 Sep 2019 18:05
por Pabloko
For this job theres already luasocket, googles basic udp client:
local socket = require("socket")
udp = socket.udp()
udp:setpeername("192.168.1.xxx", 5474)
udp:send("Data!")
To test it you can use simplest network tool "nc" from here: https://joncraton.org/blog/46/netcat-for-windows/

Open you server by running <nc.exe -u -l 5474> it will listen for udp datagrams then run your program, you must see the output on console

Re: TCP/IP Send

Publicado: 25 Sep 2019 10:15
por sendai
i Pabloko.. thanks for this.. i will study on this example hope i can get it before the deadline hahaha.. :awesome-1417754492:

Re: TCP/IP Send

Publicado: 22 Oct 2019 23:39
por Dow Sher
-- SERVER
-- load namespace
local socket = require("socket")
-- create a TCP socket and bind it to the local host, at any port
local server = assert(socket.bind("*", 0))
-- find out which port the OS chose for us
local ip, port = server:getsockname()
-- print a message informing what's up
print("Please telnet to localhost on port " .. port)
print("After connecting, you have 10s to enter a line to be echoed")
-- loop forever waiting for clients
while 1 do
  -- wait for a connection from any client
  local client = server:accept()
  -- make sure we don't block waiting for this client's line
  client:settimeout(10)
  -- receive the line
  local line, err = client:receive()
  -- if there was no error, send it back to the client
  if not err then client:send(line .. "\n") end
  -- done with client, close the object
  client:close()
end
-- CLIENT
local host, port = "127.0.0.1", 100
local socket = require("socket")
local tcp = assert(socket.tcp())

tcp:connect(host, port);
--note the newline below
tcp:send("hello world\n");

while true do
    local s, status, partial = tcp:receive()
    print(s or partial)
    if status == "closed" then break end
end
tcp:close()
HIDE: ON
Hidebb Message Hidden Description

Re: TCP/IP Send

Publicado: 23 Oct 2019 02:44
por dripro

----------------------------<< Client: >>
local socket = require("socket")
local host, port = "192.168.100.47", 51515
local tcp = assert(socket.tcp())

tcp:connect(host, port);
tcp:send("hello world\n");

while true do
    local s, status, partial = tcp:receive()
    print(s or partial)
    if status == "closed" then
      break
    end
end

tcp:close()

--------------------------------------<< Server: >>
local socket = require("socket")
local server = assert(socket.bind("*", 51515))
local tcp = assert(socket.tcp())

print(socket._VERSION)
print(tcp)

while 1 do

  local client = server:accept()

  line = client:receive()
  client:send("it works\n")

end


Re: TCP/IP Send

Publicado: 24 Oct 2019 04:02
por sendai
Hello dripo, thank you for this example codes, i already show to her but
my teacher donot want a generic string to send, she wants something like bytes


Head 2 BYTE 0xFF 0xFE
ID 1 BYTE 0x01 for general data
Length 2 BYTE 0x10 0x00 (Length=16)

still in the processes of reading some articles and other furom about it..

Re: TCP/IP Send

Publicado: 30 Oct 2019 15:57
por patch
The posts people have given you here are a starter place you send the data you want in the format you want.

Re: TCP/IP Send

Publicado: 02 Nov 2019 19:28
por FRAPIDS
:pc: . . .

Re: TCP/IP Send

Publicado: 17 Dic 2019 08:51
por sendai
Pabloko escribió:
13 Sep 2019 18:05
For this job theres already luasocket, googles basic udp client:
local socket = require("socket")
udp = socket.udp()
udp:setpeername("192.168.1.xxx", 5474)
udp:send("Data!")
To test it you can use simplest network tool "nc" from here: https://joncraton.org/blog/46/netcat-for-windows/

Open you server by running <nc.exe -u -l 5474> it will listen for udp datagrams then run your program, you must see the output on console

Hi Pabloko, i found UDP is also good in other ideas i have.. your example is very much working in nc.exe..


now i want to create a server also using UDP that once it receives datagram it will display into input object..
can you help me how to create UDP server? does it requires timer to read the datagrams?

Re: TCP/IP Send

Publicado: 17 Dic 2019 21:28
por jhonitimer
thnks all

Re: TCP/IP Send

Publicado: 23 Dic 2019 00:13
por Pabloko
sendai escribió:
17 Dic 2019 08:51
Pabloko escribió:
13 Sep 2019 18:05
For this job theres already luasocket, googles basic udp client:
local socket = require("socket")
udp = socket.udp()
udp:setpeername("192.168.1.xxx", 5474)
udp:send("Data!")
To test it you can use simplest network tool "nc" from here: https://joncraton.org/blog/46/netcat-for-windows/

Open you server by running <nc.exe -u -l 5474> it will listen for udp datagrams then run your program, you must see the output on console

Hi Pabloko, i found UDP is also good in other ideas i have.. your example is very much working in nc.exe..


now i want to create a server also using UDP that once it receives datagram it will display into input object..
can you help me how to create UDP server? does it requires timer to read the datagrams?
Luasocket will block until a datagram arrives so i suggest to use lanes or something threaded

Re: TCP/IP Send

Publicado: 23 Dic 2019 03:11
por sendai
Pabloko escribió:
23 Dic 2019 00:13
sendai escribió:
17 Dic 2019 08:51
Pabloko escribió:
13 Sep 2019 18:05
For this job theres already luasocket, googles basic udp client:
local socket = require("socket")
udp = socket.udp()
udp:setpeername("192.168.1.xxx", 5474)
udp:send("Data!")
To test it you can use simplest network tool "nc" from here: https://joncraton.org/blog/46/netcat-for-windows/

Open you server by running <nc.exe -u -l 5474> it will listen for udp datagrams then run your program, you must see the output on console

Hi Pabloko, i found UDP is also good in other ideas i have.. your example is very much working in nc.exe..


now i want to create a server also using UDP that once it receives datagram it will display into input object..
can you help me how to create UDP server? does it requires timer to read the datagrams?
Luasocket will block until a datagram arrives so i suggest to use lanes or something threaded

Did you mean use Lanes as server and UDP from client? do you have example on that? Thanks

Re: TCP/IP Send

Publicado: 23 Dic 2019 05:28
por sendai
SERVER
local socket = require("socket")
local server = assert(socket.bind("192.168.1.7", 5474))
local udp = assert(socket.udp())

on TIMER

if e_ID == 1 then
local client = server:accept()

line = client:receive()
client:send("it works\n")

Input.SetText("Input1", line)

end


CLIENT
local socket = require("socket")
udp = socket.udp()
udp:setpeername("192.168.1.7", 5474)
udp:send("Data!")


anyone can help?

Re: TCP/IP Send

Publicado: 23 Dic 2019 06:38
por sendai
anyone can help me convert this to AMS application?

https://wiki.jc-mp.com/Lua/Server/UDPSocket

Example of a receiver

local server = UDPSocket.Create() -- Creation of the socket
server:Bind(1734) -- Binding of the socket to the port 1734

function Receive(args)
print(args.ip) -- The IP this packet comes from.
print(args.port) -- The port this message comes through.
print(args.bytes) -- The size of the packet.
print(args.text) -- The actual message of the packet (to transfer tables you can use json).

server:Close() -- For some reason the socket will only accept one packet, so we have to destroy and recreate it.
server = nil
server = UDPSocket.Create()
server:Bind(1734)
server:Receive(Receive)
end
server:Receive(Receive) -- Adding the receive-handler


Example of a sender

local client = UDPSocket.Create() -- Create the socket.
client:Send("127.0.0.1", 1734, "Hello there.") -- Send a packet to the IP "127.0.0.1" (to ourselves) on port 1734 with the message "Hello there."
client:Close()

Re: TCP/IP Send

Publicado: 30 Dic 2019 11:29
por sendai
any update from this? need help.. thank you

Re: TCP/IP Send

Publicado: 01 Ene 2020 07:18
por sendai
Thanks everyone.. i already get the solutions.


Happy New year 2020!

Re: TCP/IP Send

Publicado: 10 Ene 2020 12:43
por THEBEST1
very good job: Thank you