Native Cacoa client

Posted on
Tue Apr 01, 2008 8:08 am
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

Native Cacoa client

I have managed to get connection with the Indigo server
with the AsyncSocket class

Code: Select all
NSData *message =
      [@"<Packet><Type>Authenticate</Type><Name>KnockKnock</Name><Data><ClientType>2</ClientType><DoBroadcasts>true</DoBroadcasts></Data></Packet>" dataUsingEncoding:NSASCIIStringEncoding];


Image

Posted on
Tue Apr 01, 2008 9:37 am
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

Matt, I've a question:

when I send:
Code: Select all
<Packet><Type>Authenticate</Type>
<Name>KnockKnock</Name><Data><ClientType>2</ClientType><DoBroadcasts>true</DoBroadcasts></Data></Packet>

to the server, I won't authenticate me,

I tried \r and \n at the end of the string, neither helps.
sending NSXML object gives the same symthom....

authentication time out

do you know what I'm missing ?

Posted on
Tue Apr 01, 2008 10:02 am
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

(No subject)

Hi Martijn,

The authentication timeout message means the server never received all the authentication XML packets from the client. The KnockKnock packet is the first message the client sends, then if password authetnication is enabled the server responds with a packet (called "Authenticate" with name "NeedsPassword") which includes an authentication salt string. The client then has to SHA1 hash the password, base64 encode it, append the salt string, then SHA1 hash and base64 encode that result. It then sends that to the server with an Authenticate AttemptAuthentication packet.

The communication protocol document provides the details and example packets for this. If your copy of that document doesn't include that (it may not since it is old), then let me know and I'll email you the latest copy.

FYI, after 2.5 ships, I am planning on working on the iPhone client and will also put together some source code to share that handles the basic client/server communication.

Regards,
Matt

Posted on
Tue Apr 01, 2008 11:34 am
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

I made a seperate app for testing the socket connection

Image


Xcode project 6 mb

Posted on
Tue Apr 01, 2008 11:40 am
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

The KnockKnock packet is the first message the client sends


yes I know,
What I did: I added 'export xml to log' in the Flash client
and connected, this is what I saw:

Code: Select all
<Packet><Type>Authenticate</Type><Name>KnockKnock</Name><Data><ClientType>2</ClientType><DoBroadcasts>true</DoBroadcasts></Data></Packet>
<Packet><Type>Authenticate</Type><Name>Success</Name><Data><ServerProtocolCount>3</ServerProtocolCount><ServerVersionString>version 2.5.0 b8</ServerVersionString></Data></Packet>
<Packet><Type>Request</Type><Name>GetVariableList</Name></Packet>
<Packet><Type>Request</Type><Name>GetTDTriggerList</Name></Packet>
<Packet><Type>Request</Type><Name>GetTriggerList</Name></Packet>
<Packet><Type>Request</Type><Name>GetActionGroupList</Name></Packet>
<Packet><Type>Request</Type><Name>GetDeviceList</Name></Packet>
<Packet><Type>Broadcast</Type><Name>UpdatedTimeInfo</Name><Data><CurrentTime>260385888</CurrentTime><NextSunriseTime>260435479</NextSunriseTime><NextSunsetTime>260396138</NextSunsetTime><NextTriggerTime>260394338</NextTriggerTime></Data></Packet>


As you can see no packets needed after the knockknock packet,
but when I send getdevicespackets I got a "not authenticated" client error ;(

Posted on
Tue Apr 01, 2008 11:45 am
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

this also doesn't work:


Code: Select all
  NSXMLElement *root = [[NSXMLElement alloc] initWithName:@"Packet"];
  [root addAttribute:[NSXMLNode attributeWithName:@"type" stringValue:@"dict"]];
  NSXMLElement *childElement1 = [[NSXMLElement alloc] initWithName:@"Type"];
  [childElement1 addAttribute:[NSXMLNode attributeWithName:@"type" stringValue:@"string"]];
  [childElement1 setStringValue:@"Authenticate"];
  [root addChild:childElement1];
  [childElement1 release];
 
  NSXMLElement *childElement3 = [[NSXMLElement alloc] initWithName:@"Name"];
  [childElement3 addAttribute:[NSXMLNode attributeWithName:@"type" stringValue:@"string"]];
  [childElement3 setStringValue:@"KnockKnock"];
  [root addChild:childElement3];
  [childElement3 release];
 
  NSXMLElement *childElement4 = [[NSXMLElement alloc] initWithName:@"Data"];
  [childElement4 addAttribute:[NSXMLNode attributeWithName:@"type" stringValue:@"dict"]];
  [root addChild:childElement4];
  [childElement4 release];
 
   
  NSXMLElement *childElement5 = [[NSXMLElement alloc] initWithName:@"ClientType"];
  [childElement5 addAttribute:[NSXMLNode attributeWithName:@"type" stringValue:@"string"]];
  [childElement5 setStringValue:@"2"];
  [childElement4 addChild:childElement5];
  [childElement5 release];
   
  NSXMLElement *childElement6 = [[NSXMLElement alloc] initWithName:@"DoBroadcasts"];
  [childElement6 addAttribute:[NSXMLNode attributeWithName:@"type" stringValue:@"string"]];
  [childElement6 setStringValue:@"true"];
  [childElement4 addChild:childElement6];
  [childElement6 release];
 
  NSXMLDocument *xmlRequest = [NSXMLDocument documentWithRootElement:root];
  [root release];

Posted on
Tue Apr 01, 2008 11:53 am
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

(No subject)

Martijn Heeroma wrote:
As you can see no packets needed after the knockknock packet, but when I send getdevicespackets I got a "not authenticated" client error ;(

The packet stream above doesn't have the complete authentication exchange. In the example above, the server thinks that it can skip password authentication so it doesn't request it from the client. This occurs if the connection is from the same IP address as the server, or if the password authentication is turned OFF. Try it again using the flash client from a different Mac than the server and see if you get the complete (and more complex) packet exchange.

Regards,
Matt

Posted on
Tue Apr 01, 2008 12:28 pm
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

With Flash on another mac i got this :

Code: Select all
<Packet><Type>Authenticate</Type><Name>KnockKnock</Name><Data><ClientType>2</ClientType><DoBroadcasts>true</DoBroadcasts></Data></Packet>
<Packet><Type>Authenticate</Type><Name>Success</Name><Data><ServerProtocolCount>3</ServerProtocolCount><ServerVersionString>version 2.5.0 b8</ServerVersionString></Data></Packet>
<Packet><Type>Request</Type><Name>GetVariableList</Name></Packet>


and now I see the "Authenticate-back" packet.

So I'm sending a different packet to the server than the Flash client :evil:

I think I'm going to write a simple Cocoa socketserver
than I can compare this step by step.

Posted on
Tue Apr 01, 2008 12:57 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

(No subject)

I'm still not seeing all the correct packets above. Inside the IndigoClient.as file look at both the SendAuthenticateKnock() function and the SendAuthenticatePassword() function. Above I see the former, but not the latter.

Matt

Posted on
Tue Apr 01, 2008 2:12 pm
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

I'm still not seeing all the correct packets above


That must be enough, because that gave me connection.
- My server has no password setting
- the Flashclient logs in all the time

I'll have a look if my log is missing something,
or if I have stress with line-end characters (cr-lf etc)

I strongly feel my auth. packet is not well

white spaces ?

Posted on
Tue Apr 01, 2008 2:28 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

(No subject)

Martijn Heeroma wrote:
- My server has no password setting

Gotcha. I though you had a server password and were trying to test the authentication handshake. You are just trying to connect without any password set. The packets you are seeing is correct for the case where no server password is set.

Does your authentication packet have any CR/LF characters? The entire packet should all be on a single line. The Indigo Server interprets CR or LF (and 0x00) as an end-of-packet marker.

Matt

Posted on
Tue Apr 01, 2008 3:01 pm
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

The Indigo Server interprets CR or LF (and 0x00) as an end-of-packet marker.


thanks Matt.

I think that's missing

Posted on
Wed Apr 02, 2008 10:06 am
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

Gotcha


It was stress with linebreaks, this works:

put a "\r" in front of the first packet
and a "\r" at the end of all packets.

this works (and turns off my "Spot eettafel" lamp:
Code: Select all
NSData *newline2 = [@"<Packet><Type>Command</Type><Name>TurnOff</Name><Data>Spot eettafel</Data></Packet>\r" dataUsingEncoding:NSASCIIStringEncoding];
  [socket writeData:newline2 withTimeout:-1 tag:0];


I'm so happy now, having the socket connected with sending
async "non blocking" commands to the Indigo

this is so cool, you won't hear complaints from me for the next year or
so this is all what I want, building nice Cocoa Iphone and laptop screens
for the Indigo server.

*Realtime pushed clients as many as you want*
only Indigo can do that ;)

Posted on
Wed Apr 02, 2008 1:05 pm
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

Xcode project 6 mb
Cleaned code,

This one can log in, (when password is turned of ;))
and send commands to port 1176

I cannot receive yet
(on the same socket in the same thread, I'm puzzling with the "runLoop" that I don't understand)
not yet....

Posted on
Wed Apr 02, 2008 9:14 pm
mreyn2005 offline
User avatar
Posts: 161
Joined: Oct 06, 2006

(No subject)

w00t!

Who is online

Users browsing this forum: No registered users and 2 guests