Well I was tired of using my winsock to connect to different servers and writing 3 lines of code just to get the control to connect. So I made the following function:
[color=\"red\"][size=1]* [b]Note[/b]: This is used for Microsoft Winsock Control 6.0[/size][/color]
Public Sub Connect(Server As String, Port As String)
With Winsock1
.RemoteHost = Server
.RemotePort = Port
.Connect
End With
End Sub
Syntax:
Connect \"irc.killanet.net\", \"6667\"
\'This is just an example...
Remember to replace [b]Winsock1[/b] with your own named winsock control.
Such a simple code, but such a help in your coding <img src=\'http://www.killanet.net/forum3/public/s ... >/blum.gif\' class=\'bbc_emoticon\' alt=\':P\' />
~Dren (victory)
Winsock Connect Function
Moderators: Moderator, Global Moderator
Winsock Connect Function
Last edited by Josh on Thu Oct 13, 2005 11:42 am, edited 1 time in total.
[align=center]

“If you stop learning, you stop living.” ~Tami Quiring
“It's the rare man who understands the value of a single perfect rose.”
[/align]

“If you stop learning, you stop living.” ~Tami Quiring
“It's the rare man who understands the value of a single perfect rose.”
[/align]
-
FlyingDoggyJake
- Sr. Member

- Posts: 254
- Joined: Thu Jun 17, 2004 12:37 am
Winsock Connect Function
Good idea Josh <img src=\'http://www.killanet.net/forum3/public/s ... /smile.gif\' class=\'bbc_emoticon\' alt=\':)\' /> ... sometimes these little functions end up being the most useful.
Another example of a simple little function that saves a lot of grief when using Winsocks is:
[color=\"blue\"]Public Sub SendData(Data As String)
On Error Goto err
Winsock1.SendData Data & vbCrLf
Exit Sub
err:
MsgBox \"You must establish a connection before using that control!\"
End Sub[/color]
Then whenever you want to send data you can use this function and never have to worry about your program crashing due to \"Protocol\" or \"Connection State\" runtime errors.
As Josh put it: \"Such a simple code, but such a help in your coding\"
Another example of a simple little function that saves a lot of grief when using Winsocks is:
[color=\"blue\"]Public Sub SendData(Data As String)
On Error Goto err
Winsock1.SendData Data & vbCrLf
Exit Sub
err:
MsgBox \"You must establish a connection before using that control!\"
End Sub[/color]
Then whenever you want to send data you can use this function and never have to worry about your program crashing due to \"Protocol\" or \"Connection State\" runtime errors.
As Josh put it: \"Such a simple code, but such a help in your coding\"


Winsock Connect Function
Never thought adding an \"On Error Goto err\", good thinking jake!
[align=center]

“If you stop learning, you stop living.” ~Tami Quiring
“It's the rare man who understands the value of a single perfect rose.”
[/align]

“If you stop learning, you stop living.” ~Tami Quiring
“It's the rare man who understands the value of a single perfect rose.”
[/align]