Game Development Community

Httpobject not working???

by Sebastiaan Cocu · in Torque Game Engine · 05/23/2006 (5:08 am) · 10 replies

I am trying to fix a problem in the mmorpg kit where it needs to connect to a webserver.

This works on windows and linux, but somehow fails on Mac osx.

The only error I can find is "Socket not ready to write!" which is from the macCarbNet.cc , but no other error is given. Both the normal SDK as from the CVS give this error and I am seem to go around in circles trying to figure out where it goes wrong.

About the author

Recent Threads


#1
05/25/2006 (5:30 pm)
Does the IP address you are trying to connect to have a zero anywhere in it?
Found a bug lately with connecting to IP addresses that have a 0 ( zero ) as one of the four numbers in the IP address, for example xxx.0.xxx.xxx or xxx.xxx.0.xxx, where xxx is any number [1 - 255] .

If not, try increasing the wait time in the call to select(), in macCarbNet.cc.

Also, just to check, what version of TGE or TGB are you using ?
#2
05/26/2006 (2:34 am)
Hi Scott,

Yes the ip adress for the testserver has a zero xxx.xxx.xxx.0 that explains a lot. The new demo server doesn't have it so I will test it on that.
However
I did increase a time on line 746 ( if( netSocketWaitForWritable(socket, 9999) ) // 1 millisec ought to be plenty...)
and it sorta worked, cos I got a reply from the server, just didn't have the time at that moment to see what else was wrong.
I will fine tune with the ohther mac users from the kit dev team to see what number works best.

I expect that a fix will be in 1.4.2

(I have 1.4.0, 1.4.0u and CVS and what works best I use)

Thanks for the help.
#3
05/31/2006 (3:12 pm)
Yeah, I've managed to reproduce this one, and I found a fix.
Turns out, httpObjects were getting an OnConnected event *Before* the socket was actually connected, because the getsockopt() had cleared the error state when we polled for the error state. So, Net::process() would hit a connecting socket once, then on the second try it would *always* think that the socket had connected... when it was still waiting.
This was easily fixed with the following code changes:

in macCarbNet.cc replace the function Net::send() with the following:
Net::Error Net::send(NetSocket socket, const U8 *buffer, S32 bufferSize)
{
   errno = 0;
   S32 bytesWritten = ::send(socket, (const char*)buffer, bufferSize, 0);
   if(bytesWritten == -1)
      Con::errorf("Could not write to socket. Error: %s",strerror(errno));
   
   return getLastError();
}

in macCarbNet.cc, in the function Net::process, in the case: ConnectionPending block,
insert this code:
// poll for writable status to be sure we're connected.
 bool ready = netSocketWaitForWritable(currentSock->fd,0);
 if(!ready)
    break;

before this code:
// connected.
notifyEvent.state = ConnectedNotifyEvent::Connected;
Game->postEvent(notifyEvent);
currentSock->state = Connected;

And that will sort the problem, without blocking while you wait for the socket.

Share and Enjoy.
/Paul
#4
05/31/2006 (4:21 pm)
Thank you!

I am commiting the fix to the kit as I am typing this.
Just in time for the kit demo for the Mac.
#5
06/25/2006 (5:10 pm)
Oh God thankyou.

I posted the same problem several weeks back, but never received any response. I had no idea what was causing it and no idea where in the source to start looking, so I have been getting around it using an ugly and unreliable schedule script function to delay the send.

Glad to see this has been fixed.

Thanks again.
-Davidovich
#6
08/23/2006 (7:57 am)
@Paul can't found this code in macCarbNet.cc, but i found it in x86UNIXNet.cc
// connected.
notifyEvent.state = ConnectedNotifyEvent::Connected;
Game->postEvent(notifyEvent);
currentSock->state = Connected;

it's that correct ? or i lost something :(
#7
08/23/2006 (8:34 am)
@Paul can't found this code in macCarbNet.cc, but i found it in x86UNIXNet.cc
// connected.
notifyEvent.state = ConnectedNotifyEvent::Connected;
Game->postEvent(notifyEvent);
currentSock->state = Connected;

it's that correct ? or i lost something :(
#8
08/23/2006 (11:00 am)
@Paul can't found this code in macCarbNet.cc, but i found it in x86UNIXNet.cc
// connected.
notifyEvent.state = ConnectedNotifyEvent::Connected;
Game->postEvent(notifyEvent);
currentSock->state = Connected;

it's that correct ? or i lost something :(
#9
08/23/2006 (11:27 am)
Korpos - are you perhaps using a TGE earlier than 1.4 ?
i see the lines in tge 1.4 but not in tge 1.3.
#10
08/31/2006 (12:19 pm)
@Korpos: Orion is correct. 1.4 has new Mac networking code, and the new stuff is what I'm referencing.

In general, you should probably merge your projects to 1.4, if you are still using 1.3.
Unless you have an actually shipping, selling product with 1.3, you should probably upp to 1.4.

Guys, I really mean this. Merge your stuff up to 1.4. There are a ton of fixes & goodies. That, and the old mac platform was something of a mess. It's fixed now, and is readable & maintainable by sane humans.

So check it out. It's good stuff.
1.4.2 will be out on CVS as soon as Mattf or I get a spare moment to upload it.

/Paul