mIRC Home    About    Download    Register    News    Help

Print Thread
#228964 17/01/11 04:09 PM
Joined: Jul 2006
Posts: 4,180
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,180
Not sure if it's a bug so here the suggestion, we can /sockopen to localhost, but can't /sockudp to localhost :
Code:
alias test_sock {
  sockopen test_sock 127.0.0.1 8000
  echo -a /sockopen with 127.0.0.1 is fine
  sockclose test_sock
  sockopen test_sock localhost 8000
  echo -a /sockopen with localhost is fine
  sockclose test_sock
  sockudp test_sock 127.0.0.1 8000
  echo -a /sockudp with 127.0.0.1 is fine
  sockudp test_sock localhost 8000
  echo -a /sockudp with localhost is fine
}
It would make sense for /sockudp to also accept localhost as an ip address


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Apr 2004
Posts: 871
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 871
This is not a bug, as it is documented behavior. From /help /sockudp:

Quote:
ipaddress and port specify the destination address to which you want to send information. You can only use an IP address here.

I'd guess it's a matter of implementation complexity: if mIRC were to accept hostnames there, it would have to resolve the host while keeping the packet around for sending when the resolution succeeded. It is much easier to simply send the packet rightaway, and not keep track of these things. Of course mIRC can be changed to support hostnames here, but is it really worth it?


Saturn, QuakeNet staff
Joined: Jul 2006
Posts: 4,180
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,180
I'm not sure about the complexity since it's done for tcp but you might be right.
Quote:
Of course mIRC can be changed to support hostnames here, but is it really worth it?
I have a client and a server where only the server needs to open a tcp port and a udp port.
Since the server can run with any tcp/udp ports, it's up to the client to specify an ip address and a tcp port, the client first connect to the server with tcp and then udp is done internally (the server send the udp port).
In this case when the client want to send a packet, it will use the ip address specified when connecting with tcp, and it will fail if localhost has been used.
I could do $iif(address == localhost,127.0.0.1,$v1) but it doesn't seem to be the good solution so imo, yes.

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Originally Posted By: Wims
I'm not sure about the complexity since it's done for tcp...


It's not done for TCP. TCP uses /sockopen to statefully set the remote host for the remainder of the connection. Namely, you don't /sockwrite <hostname> <data>, the hostname is already stored in the sockopen, with TCP connections. This is unlike UDP, which is not tied to a specific remote host and does need to know about the dest. IP for every packet.

Something to note: if this were to be supported and you used it, your script would become slower, since mIRC would have to resolve the <host> parameter everytime it executed. Again, this is unlike TCP, which resolves the remote host to an IP upon /sockopen. This of course assumes mIRC would not cache lookups, which I don't think it should be doing. One of the first things you'd do to optimize the script would be to remove the inline host resolution anyway, so it seems unnecessary to me.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Jul 2006
Posts: 4,180
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,180
Quote:
This is unlike UDP, which is not tied to a specific remote host and does need to know about the dest. IP for every packet.
True but :
Quote:
Something to note: if this were to be supported and you used it, your script would become slower, since mIRC would have to resolve the <host> parameter everytime it executed. Again, this is unlike TCP, which resolves the remote host to an IP upon /sockopen. This of course assumes mIRC would not cache lookups, which I don't think it should be doing. One of the first things you'd do to optimize the script would be to remove the inline host resolution anyway, so it seems unnecessary to me.
The -k switch of /sockudp let you use the same "connexion" everytime, so the cache is sort of already supported internally, this would not make my script slower.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Originally Posted By: Wims
The -k switch of /sockudp let you use the same "connexion" everytime


Not the same thing. -k only performs a bind on the local port and keeps the socket open. It does not remember the remote ip/port, and that is not its purpose. Many scripts that use sockudp -k listen for packets from varying remote hosts and can respond to any arbitrary remote host within the course of a connection, aka. the .saddr can change between UDPREAD events. The sockudp port bug that you recently reported summarized this state of affairs quite well.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Jul 2006
Posts: 4,180
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,180
Hum that's right, I'll use that $iif if I want to support localhost then


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard