Page 1 of 1

Winsock Connect Function

Posted: Fri Oct 15, 2004 2:58 am
by Josh
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 /blum.gif\' class=\'bbc_emoticon\' alt=\':P\' />

~Dren (victory)

Winsock Connect Function

Posted: Mon Oct 18, 2004 2:51 pm
by FlyingDoggyJake
Good idea Josh /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\"

Winsock Connect Function

Posted: Mon Oct 18, 2004 9:45 pm
by Josh
Never thought adding an \"On Error Goto err\", good thinking jake!