| |

Visual-Basic EinsteigerRe: IRC-Client mit VB? | |  | Autor: bascaro | Datum: 22.04.04 14:07 |
| hab jetz schon was gefunden und hilfe über irc bekommen hier das tutorial
____________________________
Create a new project, with a Winsock control on it, call it sock in the properties box. Create a button called cmdConnect, and label it ‘Connect/Disconnect’ or something similar. Create one big (tall – say 10 – 15 lines) text box, with ‘MultiLine’ set to True, ‘Scrollbars’ set to ‘Vertical’, call that txtMessages. Then create a smaller box along the bottom called txtInput (1 line high). Finally, create a list box, called lstQueue.
It’ll become clear soon what all of these are for – you can probably work it out.
Double click on the cmdConnect, to see the cmdConnect_Click code. This is where we initiate the IRC connection. I’ve chosen to put the server logging-in code here, though you could put it in the sock_connect. Put this code in:
Sock.Connect "irc.quakenet.eu.org", 6667
Do Until sock.State = sckConnected
DoEvents
Loop
strEmail = "foo@bar.com"
strRealName = "foo bar"
strNickName = "fb2k"
IRCSEnd "USER " & strEmail & " " & sock.LocalHostName & " " & sock.LocalHostName & " :" & strRealName
For i = 0 To 100
DoEvents
Next i
IRCSEnd "NICK " & strNickName
This uses two IRC commands. USER and NICK. I won’t bother to explain all the IRC commands I use in this tutorial. It would take too long. You can use the RFC to look up anything that isn’t obvious. Basically though, USER sends your details, and NICK registers your nick name. The lines between For … and Next I, just make it wait for a few mili seconds, otherwise you may get an error message from the server.
You may notice that I’ve used a function called IRCSend. This is what we’re about to write. This function does two things, firstly it adds a CR-LF pair to the end of the text, and secondly it adds it to the send queue. I haven’t explained about the CR-LF yet. CR-LF, and it’s manifestation in VB as vbCrLf are used in the IRC protocol (and many others) as end of line characters. This means that at the end of EVERY line in IRC there must be a CR-LF pair. This is why I use a function for this. It saves me having to remember, and also means I have less to type. Here goes. Put this sub in:
Sub IRCSEnd(strData As String)
lstQueue.AddItem strData & vbCrLf
txtMessages = txtMessages & "> " & strData & vbNewLine
txtMessages.SelStart = Len(txtMessages) - 1
End Sub
That should be quite self explanatory. lstQueue, you will remember is a list box. This is used to queue up all the data that is waiting to be sent, so as not to be kicked off IRC for flooding, it is sent, by a timer (we’re about to code it) every two seconds (the time set by the RFC). Then the code adds the data to the messges box (txtMessages), and scrolls it to the bottom (the final line).
Now the Timer. Create a Timer, call it tmrSend. Set the interval to 2000 (2 seconds). The double click it to enter some code in the Timer event:
If lstQueue.ListCount <> 0 and sock.State = sckConnected Then
sock.SendData lstQueue.List(0)
lstQueue.RemoveItem (0)
End If
That’s pretty obvious too. In English: If the sockets connected, and the list isn’t empty, then send the first item in the list through the socket, and then delete it from the list.
By this point you should have a client that can connect to your irc server, and not much else. If you’ve used IRC, you’ll know (almost certainly) about PING and PONG. These are two commands, one – PING – is a server query to check that the client is still connected. PONG is the reply. PING isn’t just sent on its own though. It is sent with either a number or the server name after it like:
PING :irc.quakenet.eu.org
To this you would reply:
PONG :irc.quakenet.eu.org
Very simple eh? Yep. So heres our first code that goes in sock_dataarival:
Dim strData As String
sock.GetData strData
strLines = Split(strData, vbCrLf)
strLineParts = Split(strLines(i), " ")
txtMessages = txtMessages & "<" & strData & vbNewLine
txtMessages.SelStart = Len(txtMessages) - 1 ' scroll it
For i = 0 To UBound(strLines)
strLineParts = Split(strLines(i), " ")
If UBound(strLineParts) <> -1 Then
Select Case strLineParts(0)
Case "PING"
IRCSEnd ("PONG " & Trim(Right(strData, Len(strData) - Len("PING "))))
End Select
End If
Next i
You now have a working IRC client. You can't actually send or recieve text yet, but you'll be able to soon!
______________________________
kann mir jemand sagen wie weitere commands von irc sind? |  |
 | Sie sind nicht angemeldet! Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
  |
|
vb@rchiv CD Vol.6 vb@rchiv Vol.6
Geballtes Wissen aus mehr als 8 Jahren vb@rchiv!
Online-Update-Funktion Entwickler-Vollversionen u.v.m.Jetzt zugreifen Tipp des Monats Oktober 2025 Matthias KozlowskiUmlaute konvertierenErsetzt die Umlaute in einer Zeichenkette durch die entsprechenden Doppelbuchstaben (aus ä wird ae, usw.) sevOutBar 4.0 
Vertikale Menüleisten á la Outlook
Erstellen von Outlook ähnlichen Benutzer- interfaces - mit beliebig vielen Gruppen und Symboleinträgen. Moderner OfficeXP-Style mit Farbverläufen, Balloon-Tips, u.v.m. Weitere Infos
|
|
|
Copyright ©2000-2025 vb@rchiv Dieter Otter Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.
Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel
|
|