Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock example request 1

Status
Not open for further replies.

Reuel

Programmer
Dec 27, 2004
45
0
0
US
I'm at work where I can't get to any help files for winsock. Can somebody give me a quick example of the code required to create a winsock instance, including telling it to listen and respont to internet requests? I'm going to attempt to make MS Access act like a simple server, and I just don't have the resources here to get it running. Thanks!
 
Add the Microsoft Winsock Control 6.0 (MSWINSCK.OCX) to the list of components. Place the component on your form and tell the component to listen to a port you specify (1000 in this example):

with winsock
.Close
.LocalPort = 1000
.Listen
end with



 
Ok. Let me be more specific. I should have been before. I need to create the control through code. I can not put a winsock control of any type on a form, as it isn't available to me at work.
 
csocket isn't going to work with MS Access. I just spent the last 30 minutes trying to get the modules to not have red (errors) in them. I'm hoping to use the winsock API, but Microsoft's web site only shows C?? code.
 
Any reason that the Winsock control isn't available? As far as I know it's a standard component of all versions of VB except the Learning version, which you obviously won't be using for commercial development.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Have you considered Catalyst's SocketWrench Freeware Edition?

CSocket has some just incredible warts. I won't call them bugs because if you hold your mouth right it can be made to work as a private class in a VB program. Wrapping it as an ActiveX DLL resulted in nothing but flaky operation for me though. It holds a listener socket "bound to" a port when it shouldn't just for starters. It attempts some really weird object lifetime management through several private collections as well, resulting in erratic behavior.

What you probably want is some sort of free and unlicensed ActiveX DLL (or control that'll operate as a DLL, without a container) that provides a Winsock interface that looks a lot like the Winsock control. I don't think there is anything like that out there, certainly nothing I can recommend.

A server will be a tough thing to implement single-threaded without async operation. Even if you had such a DLL I'm not sure how you'd write a server that could handle more than one connected client at a time. I doubt VBA allows a With Events array of objects any more than VB6 does. This is why the Winsock control is a control in the 1st place: to permit the use of a control array.

Truthfully, in your situation I'd probably try something else... like writing an HTA. To get the necessary Winsock interface I'd have to break/bend the licensing terms of Microsoft's Winsock control in one of two ways:

[ul][li]Write a VB ActiveX control library that wraps the Winsock control (definately illegal, read the terms).[/li]
[li]Create an IE license package for the Winsock control via LPKTool (might be perfectly legal if you develop using Visual Studio).[/li][/ul]

Both require a Winsock control developer license on a development system, but the end product is portable to other systems.

Since you don't have Visual Studio (or at least VB Pro) licensed for the machine you want to develop on, both of these are illegal for you.

So you might want to look at Catalyst's offering instead.


Problem is, the freeware product is only made available as an OCX. Even if VBA can create a functional instance as a code component (like a DLL) this may not work for you either for the reason already outlined: the With Events array problem.

But I may be all wet, I'm not a heavy VBA guy by any stretch of the imagination.


There is a project out there just waiting for somebody with time on his hands:

Severely rewrite and debug CSocket, it's a good start. Then package it as an ActiveX DLL that exposes two classes. One, a basic single-socket much like the Winsock control. The other, a fancy collection class that's a "server" and contains an embedded listener socket and a collection of service sockets that it hands off connection requests to. Most typical socket events could be bubbled up to the program that instantiates the server class.

Throw it out there as freeware and a lot of scripters and VBA guys might be grateful. Just a thought.
 
As advised, since I'm doing this with Access VBA, I posted the question over there instead. If you're interested in more details I've added about why I'm doing such a thing, here's the link.
I did recently create a Visual Basic application that passes web pages through my home computer so I can get to blocked content from work. I only wanted to see if I could do it. Due to a lack of multithreading in VB6, I set up arrays of matching winsock and internet transfer controls, used flags and timers, and got it to work. It's slow, but it works. It was mostly just a personal attempt to learn how to do stuff.

Thanks to all who helped here!
 
> Due to a lack of multithreading in VB6

I'd do a search in this forum, if I were you ...
 
I did that search. As Homer would say, "Woohoo!" Funny how I find the answer to something when I was trying to do something else. I was looking for memory at a local computer store when I found a couple LinkSys Instant PowerLink modules for $10, thereby solving my "how am I going to network my home without having wires lay across the floor or spending lots of money on wireless stuff?" question.
 
<snip> Funny how I find the answer to something when I was trying to do something else. <snip>

It's usually the way. In my case normally after I've spent a lot longer than necessary doing the task in a more difficult way. :)

Ed Metcalfe.

Please do not feed the trolls.....
 
I know i'm digging up an old topic but i got this error and i don't know what to do.

First, i have to tell you that i'm quite new to winsocks in VB6 so, don't start eplaining in very complex terms.

So, here it goes :

I installed VB6 on my computer and then, i added the winSock control in the toolbar, but when i select it and try to create one in the form interface, the following message appears :

License information for this component not found. You do not have an appropriate license to use this fonctionnality in the design environment.

What can i do for it to work ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top