Computing.Net > Forums > Programming > VB 6.0 winsocket

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VB 6.0 winsocket

Reply to Message Icon

Original Message
Name: newbie1
Date: February 4, 2004 at 20:45:43 Pacific
Subject: VB 6.0 winsocket
OS: xp
CPU/Ram: 256
Comment:

I am trying to pick up some VB winsocket programming skill, but not having a lot of luck getting started. I use the help file that comes with ms visual studio and found some code to set up a basic client server program using winsokets. I went down the list of stuff to do to creat the server program and it says on step 4 to draw a winsock control on the form and change its name to tcpServer. Heres where i am haveing the problem. I look on the tool bar for a button that says winsocket control or somthing like that and i see nothing. I go to the project window and select components and see a box i can check for winsockets 6.0 under the controls tab. Is this what I want? I have read alot of documentation tonight on the web and in the help file and in some of my books, but found nothing concrete that said this is how to set it up. I just found this by snooping around. If anyone can help, i would appreciate it.


Report Offensive Message For Removal


Response Number 1
Name: Infinite Recursion
Date: February 5, 2004 at 10:16:10 Pacific
Reply: (edit)

"see a box i can check for winsockets 6.0 under the controls tab. Is this what I want?"

Yes. You want the Winsock control...

When I get home, and if I remember... I will put in a few little commands here to help you out a bit. Its some fairly straight forward code...

IR


Report Offensive Follow Up For Removal

Response Number 2
Name: newbie1
Date: February 5, 2004 at 15:39:54 Pacific
Reply: (edit)

Hey, thanks IR. I knew that was probably an obviouse choice, but when you don't know it seems alittle to easy, plus the instruction said to draw a winsock control. I though they may have ment to draw a command button or somthing. Anyway, if you could help me out abit i would appriciate it. I'm guessing you have ms visual studio. If you do, and you want to get a little better of a picture of where i am at with this, go to the help menu and type in winsock control. Dclick on it and choose the option that says using the winsock control for VB. It is with in these instructions there is a skeleton of a server program and a client program. My plan was to get these working and then i can build from them. Specifically, I could add some code to ask client for a username and password and check a database for it or somthing. Don'tknow, just in the building stage. Will probaly have somthing much different when i actually get done with this. Thanks a million!


Report Offensive Follow Up For Removal

Response Number 3
Name: Infinite Recursion
Date: February 5, 2004 at 16:50:45 Pacific
Reply: (edit)

"draw a winsock control"

That means to click and drag it from your tool box onto your canvas (your main form).
It will be in your toolbox after you select it as a desired component.

On a fairly old project of mine.. I have a winsock being used... I named it, wskClient1.

Some code associated with it is:
wskClient1.LocalIP 'Gets the local IP

wskClient1.SendData (s) 'Sends the contents of s (a string) over to the server.

Form Load can have stuff like this...

With wskClient1
.Protocol = sckUDPProtocol
.RemotePort = 5000
.RemoteHost = .LocalIP
.Bind 4000
End With

With wskClient2
.Protocol = sckUDPProtocol
.RemotePort = 4000
.RemoteHost = .LocalIP
.Bind 5000
End With


This is one form acting as client and server (you can change one of the winsocks up to be a remote server, by changing the IP, etc.)

Data arrives to a winsock control in this method...

Private Sub wskClient1_DataArrival(ByVal bytesTotal As Long)
...
wskClient1.GetData strData 'Gets the data
'do something
...
End Sub

---

The above, may confuse you... but don't let it. Its fairly simple.

To get data via the Data Arrival event:
wskClient1.GetData myString

To send data:
wskClient1.SendData strData

Setting up the winsock on form load...
wskClient1.Protocol = sckUDPProtocol
wskClient1.RemotePort = 5000
wskClient1.RemoteHost = .LocalIP
wskClient1.Bind 4000


That either helped out or confused the hell out of you, let me know if you need clerification.

IR


Report Offensive Follow Up For Removal

Response Number 4
Name: newbie1
Date: February 6, 2004 at 14:32:39 Pacific
Reply: (edit)

Please help! I need it, i am about to go insane over what I know is a simple error. I can't figure it out cause i havent used VB6 that much. Note: This code came strait out of the ms help. tcpClient is the name of my winsuck control and tcpServer is the name of the winsuck control on the server program. I have both forms in the same project. The problem i am running into is the programs explode!! when the tcpClient.Connect line of code is reached. IR I have studied your code and it looks pretty much identical to what i have except for the protocol. Is there anything wrong with using TCP? I don't know, please help, someone! Thanks in advance!

Client:
Private Sub Form_Load()
' The name of the Winsock control is tcpClient. 'Laptop is the computer's
name, as shown here.
tcpClient.RemoteHost = "Laptop"
tcpClient.RemotePort = 1050
tcpClient.Connect
End Sub

Server:

Private Sub Form_Load()
' Set the LocalPort property to an integer.
' Then invoke the Listen method.
tcpServer.LocalPort = 1050
tcpServer.Listen
frmClient.Show ' Show the client form.
End Sub


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software