URLs not working with TCPObject
by Derik Wilson · in Technical Issues · 09/13/2008 (2:27 pm) · 14 replies
Hi! I have been out of the scripting game for some time; however, I don't think my memory is this bad.
Problem: When connecting to a chat server from a chat client using a TCPObject, the server accepts the connection, but then disconnects when passing a URL instead of an IP (e.g. "localhost:20010"). When passing an IP it works fine (e.g. "192.168.10.101:20010").
Here is the way I declare my TCPObject object and open a connection:
Nothing is different between the two connection attempts aside from using a URL instead of an IP.
Any help is greatly appreciated.
Problem: When connecting to a chat server from a chat client using a TCPObject, the server accepts the connection, but then disconnects when passing a URL instead of an IP (e.g. "localhost:20010"). When passing an IP it works fine (e.g. "192.168.10.101:20010").
Here is the way I declare my TCPObject object and open a connection:
function chatConnect(%server,%port,%nick)
{
// build address string (server:port)
%address = $Pref::Server::URL @ ":" @ $Pref::Server::Port;
echo("address is " @ %address);
// create a new TCPObject for our network code
new TCPObject(chatConnection);
// attempt to connect to the server
chatConnection.connect(%address);
}This is the server side code accepting the connection and storing the client:function chatConnection::onConnectRequest(%this,%address, %id)
{
// create a new TCPObject, and pass the new socket ID in as an argument
%client = new TCPObject(chatClient,%id);
// Record our new client
// Notice that we save the new TCPObject in the clientID slot. This allows us to not
// only cross reference later, but to use it to send and receive for that client.
// We can actually make calls off it. $clients[%i,"clientID"].function() is a valid call.
%i = findOpenClientSlot();
$clients[%i,"clientID"] = %client;
$clients[%i,"clientNickname"] = "guest";
$clients[%i,"connected"] = true;
$clients[%i,"ActiveRoom"] = "public";
}When I use an IP address everything works fine and I can interact with my server. However, if I specify a URL instead, the console shows the server recognizing that there is a connection request, but it does not connect. It goes through the onConnectionRequest, and then goes straight to the onDisconnect() method.Nothing is different between the two connection attempts aside from using a URL instead of an IP.
Any help is greatly appreciated.
#2
09/13/2008 (3:34 pm)
Just for the record, I DO get a response when I ping "localhost" so the DNS service is definitely working. Still, using TCPObject, when passing in "localhost:port" it finds the server because the server ackknowledges the client connection attempt, but it goes immediately to the onDisconnect.
#3
127.0.0.1 localhost
which is the loopback IP. That is working because, like I said before, I can PING "localhost" in the command prompt and it works fine.
09/13/2008 (3:50 pm)
Yes it is posted as:127.0.0.1 localhost
which is the loopback IP. That is working because, like I said before, I can PING "localhost" in the command prompt and it works fine.
#4
09/13/2008 (4:01 pm)
There is nothing wrong with my DNS. I host different servers, they are all working with URLs. The ONLY thing that does not resolve correctly (or at least it appears that way) is when I pass a URL and port number to TCPObject. When I pass an IP it works fine. So, it does appear that something is wrong with my DNS, but so far I have not found any problems with it.
#5
09/13/2008 (4:26 pm)
Yeah, tried that and same problem. I can ping both "localhost" and "derik". Like I said, the problem is NOT THE DNS!!!! I have never had to make a new entry like that in order to host a torque application. Like I have been saying, the server DOES SEE THAT I AM TRYING TO CONNECT, but it just kicks me immediatly into the disconnect logic. There has to be something I am missing on the server side (in the application, not the windows operating system, nothing wrong there). And I will mention again, when I use the IP address, either 192.168.10.102, or 127.0.0.1 , or my external IP address (the one for my router), I can connect from any PC just fine, even when I am on the same PC as the server.
#6
09/13/2008 (5:14 pm)
Well there was someone here proposing solutions, but he deleted all his posts.
#7
09/13/2008 (5:58 pm)
Derik, just to be sure, you are passing in "localhost:20010", not "http://localhost:20010", yeah ?
#8
And as I said in the posts above when I was talking the that other guy (the one who deleted his possible solutions), I can see on the server in the console that a client connected, then disconnected. It will let me connect but then disconnects immediately, and only when I use a host name and not the IP. If I was including "http" in the URL string, it would not have found the server.
09/13/2008 (6:43 pm)
Yeah. I am only passing the host name, in this case, localhost, or pcgamedev.selfip.net. Neither work, yet I can ping them from the server.And as I said in the posts above when I was talking the that other guy (the one who deleted his possible solutions), I can see on the server in the console that a client connected, then disconnected. It will let me connect but then disconnects immediately, and only when I use a host name and not the IP. If I was including "http" in the URL string, it would not have found the server.
#9
09/13/2008 (8:08 pm)
Ok, we just tested this on two other PCs and passing a host name does not work on any of them. They ALL connect if using the IP address. Either they have changed the way we are to use TCPObject, or, there is something wrong with my server code, but I cannot imagine what. It is pretty cut and dry.
#10
09/13/2008 (9:01 pm)
Ok, we just tested this on two other PCs and passing a host name does not work on any of them. They ALL connect if using the IP address. Either they have changed the way we are to use TCPObject, or, there is something wrong with my server code, but I cannot imagine what. It is pretty cut and dry.
#12
This does not affect passing URL vs. IP, that is still a problem. But, I hope that it is a problem with my code and not the actual TCPObject class.
09/14/2008 (2:00 pm)
I am rewriting the server. I have found a number of things that do not work as I thought they did and I have found very little good detailed documentation on them. For example, when I create a client socket/connection, I had thought that when I disconnect them (e.g. $client.disconnect()) that it would go to the onDisconnect() callback. I was wrong, it only goes there if the client disconnects themselves, so, I had some cleanup logic in the onDisconnect() that was not being executed.This does not affect passing URL vs. IP, that is still a problem. But, I hope that it is a problem with my code and not the actual TCPObject class.
#13
I have deleted all my posts because isnt useful. To reduction your post :)
09/15/2008 (8:06 pm)
*Derik* hiI have deleted all my posts because isnt useful. To reduction your post :)
#14
01/18/2009 (11:18 am)
I know this was a long time ago. I no longer have any problems with this like I was having, but I am now using TGEA 1.8.0, so I have no idea what the problem was originally. Anyway, it's not happening any more.
Torque Owner Derik Wilson