[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luasocket question
- From: Peng Zhicheng <pengzhicheng1986@...>
- Date: Sun, 13 Apr 2014 10:56:42 +0800
On 04/12/2014 05:27 PM, Ulrich Schmidt wrote:
I am using lua5.2 on windows7. (shortend code below.)
using taskmanger i see my prog listening on tcpv6 but tcp.
probably my quick fix is the easiest way to force listening on tcp insted tcpv6. the old game client i want to comunicate with seems unable to use tcpv6.
--8<---------------------------------------------------
socket = require("socket");
host = host or "localhost";
port = port or "10300";
--socket.tcp6 = socket.tcp -- quick hack
server = assert(socket.bind(host, port));
ack = "\n";
while 1 do
print("server: waiting for client connection...");
control = assert(server:accept());
print("server: incoming connection...");
while 1 do
command, emsg = control:receive();
if emsg == "closed" then
control:close()
break
end
assert(command, emsg)
assert(control:send(ack));
--print(dumpHex(command));
--print(dumpDec(command));
end
end
--8<---------------------------------------------------
greetings.
Ulrich.
Am 11.04.2014 15:34, schrieb Justin Cormack:
On Apr 10, 2014 12:10 PM, "Ulrich Schmidt" <u.sch.zw@gmx.de
<mailto:u.sch.zw@gmx.de>> wrote:
>
> Hi.
> i downloaded and installed luasocket from luadist. all test run fine.
>
> i tried a tcp server but he listen on a TVPV6 port instead TCPV4.
>
> Any suggestions how to listen on TCPV4?
>
It is probably an ipv4 mapped ipv6 socket so you can still connect to it
over ipv4.
Otherwise it would help to know your OS and a short example program.
Justin
if you want only ipv4, then you may just bind your socket explicitly
to an ipv4 address instead of the `localhost' host name.
for example,
socket.bind("127.0.0.1", port)
will bind to the ipv4 address of the loopback interface, while
socket.bind("192.168.XXX.XXX", port)
or some address similar will bind to the specified interface. and
socket.bind("0.0.0.0", port)
will bind to ipv4 addresses of every configured interface.
to explicitly bind to ipv6 address, use an ipv6 address instead. for
example, "::1" is the ipv6 address of the loopback interface.