IonicWind Software

IWBasic => Network Client/Server programming => Topic started by: WayneA on December 17, 2009, 05:12:15 AM

Title: IRC troubles
Post by: WayneA on December 17, 2009, 05:12:15 AM
Ever since the last post here about someone writing an IRC client, I have been working on my own IRC client off and on. I've done enough tweeking and research without success now that I doubt I'll ever figure this out on my own  :-\

I seemingly have the basic idea of writing a simple IRC client down since I've written 3, one each in 3 other BASIC dialects. One of those being VB6 and the other two are syntacticly very similar. I've noticed some IRC servers are more picky about what they want the client to say to them, however irc.freenode.net and irc.wildirc.net are both pretty loose and my other IRC clients easily connect and communicate with them so I have been stuck with them only when testing my EB client.

My latest attempt is below. What I'm expecting is to tell it my username, pick a nick and just connect to a channel, however I'm only able to connect and after that its almost like the server isn't getting my messages at all.

$Define USER "USER random9090 \"localhost\" \"whatever\" :blarg\n"
$Define NICK "NICK random9090\n"
$Define SERVER "irc.wildirc.net"
$Define PORT 6667
$Define JOIN "JOIN #test\n"
AutoDefine "Off"
SetID "SckMessage",0xBBBB
Declare Import,GetSysColor(nIndex As Int),Int
Dim wndMain As Window
Dim ircsck,scksts As Int
OpenWindow wndMain,0,0,500,500,@MinBox,0,"IRC",&wndMainProc
SetWindowColor wndMain,GetSysColor(15)
WaitUntil wndMain=0
NCSCloseSocket(ircsck)
NCSFree()
End

Sub wndMainProc
Dim l,t,h,w As Int
Dim buff[1024] As IString
Select @Class
Case @IDCreate
GetClientSize wndMain,l,t,h,w
Control wndMain,@Edit,"",8,8,w,h-60,@Border|@CTEditMulti|@VScroll|@CTEditAutoV|@CTEditRO,1
Control wndMain,@Edit,"",8,h-50,w,25,@Border|@CTEditAutoH,2
scksts=NCSInit(1,0)
If scksts<0 Then
Out("Error: scksts=NCSInit(1,0):")
Out(NCSGetErrorText())
Return
Else
scksts=NCSConnectToServer(SERVER,PORT)
If scksts<0 Then
Out("Error: scksts=NCSConnectToServer(SERVER,PORT):")
Out(NCSGetErrorText())
Return
Else
ircsck=scksts
Out("Connected to "+SERVER+":"+Str$(PORT)+".")
scksts=NCSOnDataMessage(wndMain.hWnd,ircsck,@SckMessage)
If scksts<0 Then
Out("Error: NCSOnDataMessage(wndMain.hWnd,ircsck,@SckMessage)")
Out(NCSGetErrorText())
Return
EndIf
EndIf
EndIf
NCSSendData(ircsck,USER,Len(User))
NCSSendData(ircsck,NICK,Len(User))
NCSSendData(ircsck,JOIN,Len(Join))
Case @SckMessage
scksts=NCSReadData(ircsck,buff,1023,2000)
If scksts>0
buff[scksts]=0
Out(buff)
EndIf
Case @IDCloseWindow
CloseWindow wndMain
EndSelect
Return
EndSub

Sub Out(o As String)
Dim ln=Len(GetControlText(wndMain,1))+Len(o) As Int
SetControlText wndMain,1,GetControlText(wndMain,1)+o+"\n"
ControlCMD wndMain,1,@EDSetSelection,ln,ln
Return
EndSub


What am I doing wrong here?
Title: Re: IRC troubles
Post by: chris on December 17, 2009, 09:24:46 AM
i'm not sure what the problem is, with my client i used the irc example paul has for sale. Maybe try looking at that?
Title: Re: IRC troubles
Post by: WayneA on December 18, 2009, 01:54:33 AM
I was forced to purchase 2 licenses for emergence basic because of the changes to how Paul is licensing his products and the license I have for aurora is near useless because the previous freeware edition of it is a more (though not as much as the new licensed version) updated version than the one I purchased.

I am unwilling to also pay $25 (more than the current cost for an emergence basic license) for the source to an IRC client just so I could get some support on the support forums that I paid to have access too (with my multiple Ionic Wind product licenses).

Also I am currently unemployed and temporarily disabled so I couldn't afford it even if I was so inclined to purchase it.
Title: Re: IRC troubles
Post by: J B Wood (Zumwalt) on December 18, 2009, 08:35:07 AM
Exactly where does it fail?
I am on vacation until the 28'th maybe I can help.
Title: Re: IRC troubles
Post by: WayneA on December 18, 2009, 01:10:03 PM
It appears that none of the data I am sending to the server is being received, the server doesn't even tell me that I sent an invalid command it just tells me it hasn't received anything at all and eventually disconnects. This happens even though all indications are that the send functions were sucessful and even when I have spammed the server with the register info dozens of times in a loop.
Title: Re: IRC troubles
Post by: J B Wood (Zumwalt) on December 18, 2009, 02:44:04 PM
Well, from what I know about networking and I will give your code a try here shortly, is that the server needs to know when the data has finished by some means, either the packet buffer has met its size or some trigger states that the client is through sending to the server, so as long as the send command actually does send the data, the server should receive that data into a buffer then go through your case statement to determine what it belongs to, so maybe the message is never seen as completed on the server. Just got ma lazy butt out of bed, looking at the code and seeing what it does or what it doesn't do.
Title: Re: IRC troubles
Post by: Copex on December 19, 2009, 03:57:48 AM
Quote from: WayneA on December 18, 2009, 01:10:03 PM
It appears that none of the data I am sending to the server is being received, the server doesn't even tell me that I sent an invalid command it just tells me it hasn't received anything at all and eventually disconnects. This happens even though all indications are that the send functions were sucessful and even when I have spammed the server with the register info dozens of times in a loop.

i have ran the code through a network monitor the data is been sent on port 6667 i can see the nick and user requests packets been sent. it seems the buffer is not been cleared

you send the first request nick then the second request you can see the nick as well as the user data in the secon headder. adding a 10ms pause after each send request seem to sort it out 
Title: Re: IRC troubles
Post by: Copex on December 19, 2009, 05:11:58 AM
Your problem is you are not sending LF & CR
Title: Re: IRC troubles
Post by: J B Wood (Zumwalt) on December 19, 2009, 01:24:35 PM
Append the line feed and return to the end of your messages, that should fix that problem.
I didn't look at the packets themself like Copex did, so I switched to the NCS_chat_client and the NCS_chat_server and tested those, which works, by the way, use ports higher than 10,000 I always typically start the server in the 10xxx range and the clients in the 11xxx range myself.

Grab the code from here, also, make sure your firewall has the port open or it will fail, the server is dedicated, so start 2 instances of the client to chat between them.
Title: Re: IRC troubles
Post by: WayneA on December 20, 2009, 03:56:11 AM
I believe that the \n escape sequence appends the CRLF, which is in the initial code I posted.

If it was modified in a way that it now works, can that working code be posted? Also, I inserted some 10ms sleeps without any benefit.

Thanks for all the help so far guys!
Title: Re: IRC troubles
Post by: Copex on December 20, 2009, 07:11:25 AM
Quote from: WayneA on December 20, 2009, 03:56:11 AM
I believe that the \n escape sequence appends the CRLF, which is in the initial code I posted.

If it was modified in a way that it now works, can that working code be posted? Also, I inserted some 10ms sleeps without any benefit.

Thanks for all the help so far guys!

\n = linefeed (newline) you also nead to send a CR (carage return) so in C you would write "\n\r" at the end of each line but EB dose not support \r so you could use "\n" +chr$(13) or  +chr$(10)+chr$(13)

the join command dont work, but it connects to the server and you can send a private message to the user and it is displayed on screen, no offence i would have to rewrit it from scratch to get it to work correctly
im realy bad when it comes to other peoples code, just wanted to prove the CR was all the code required, so i edited you code so it would connect to a server.

i change the server to freenode to test, wildirc connects and you get a PING from the server. im not sure why the join command dont work but atleast it now connects,


DECLARE "kernel32",Sleep(dwMilliseconds:INT)

string USER = "USER random9090 \"localhost\" \"whatever\" :blarg\n"+chr$(13)
STRING NICK = "NICK random9090\n"+chr$(13)
$Define SERVER "irc.freenode.net"
$Define PORT 6667
string JOIN = "JOIN #randomroom909090\n"+chr$(13)
AutoDefine "Off"
SetID "SckMessage",0xBBBB
Declare Import,GetSysColor(nIndex As Int),Int
Dim wndMain As Window
Dim ircsck,scksts As Int
OpenWindow wndMain,0,0,500,500,@MinBox,0,"IRC",&wndMainProc
SetWindowColor wndMain,GetSysColor(15)
WaitUntil wndMain=0
NCSCloseSocket(ircsck)
NCSFree()
End

Sub wndMainProc
Dim l,t,h,w As Int
Dim buff[1024] As IString
Select @Class
Case @IDCreate
GetClientSize wndMain,l,t,h,w
Control wndMain,@Edit,"",8,8,w,h-60,@Border|@CTEditMulti|@VScroll|@CTEditAutoV|@CTEditRO,1
Control wndMain,@Edit,"",8,h-50,w,25,@Border|@CTEditAutoH,2
scksts=NCSInit(1,0)
If scksts<0 Then
Out("Error: scksts=NCSInit(1,0):")
Out(NCSGetErrorText())
Return
Else
scksts=NCSConnectToServer(SERVER,PORT)
If scksts<0 Then
Out("Error: scksts=NCSConnectToServer(SERVER,PORT):")
Out(NCSGetErrorText())
Return
Else
ircsck=scksts
Out("Connected to "+SERVER+":"+Str$(PORT)+".")
scksts=NCSOnDataMessage(wndMain.hWnd,ircsck,@SckMessage)
If scksts<0 Then
Out("Error: NCSOnDataMessage(wndMain.hWnd,ircsck,@SckMessage)")
Out(NCSGetErrorText())
Return
EndIf
EndIf
EndIf
sleep(10)
NCSSendData(ircsck,USER,Len(User))
sleep(10)
NCSSendData(ircsck,NICK,Len(User))
sleep(10)

Case @SckMessage
scksts=NCSReadData(ircsck,buff,1023,2000)

If scksts>0
buff[scksts]=0
Out(buff)
EndIf
Case @IDCloseWindow
CloseWindow wndMain
EndSelect
Return
EndSub

Sub Out(o As String)
Dim ln=Len(GetControlText(wndMain,1))+Len(o) As Int
SetControlText wndMain,1,GetControlText(wndMain,1)+o+"\n"
ControlCMD wndMain,1,@EDSetSelection,ln,ln
Return
EndSub