Question

Problem with Winsock Control

Asked by: bubbles

I have made an application, that uses the winsock control to send and receive data on our home network. We have three computers, and the app is used for things like messaging etc. The problem I have is that when I want to send a message, I have to specify the computers IP address for the 'RemoteHost' property. If I give an actual machine name, I get the error 'Invalid procedure call or argument (Error 5)'

I see in the VB Help files etc. that you can specify a machine name here, rather than an IP. Can anyone tell me the problem? Is it to do with the way my TCP/IP protocol is setup? Any help would be appreciated. By the way, I have tried just about everything, so telling me to make sure that I have got the machine name right or something like that will be a waste of time.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
1999-09-13 at 15:21:40ID10205695
Tags

procedure

,

winsock

,

call

Topics

Visual Basic Programming

,

Winsock

Participating Experts
5
Points
300
Comments
17

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Winsock
    Hi, I'm using the winsock control in visual basic 5 entp and i was trying to send files over a tcp connection. I'm not sure what I have to do. Do I have to put the file into a variable...if so how do i do that? So what im asking is if you can please tell me how to send one fi...
  2. Winsock Remotehost
    I am trying to send an email via winsock to a specific email address. How do I resolve the remotehost, and are there any other properties I need to set.
  3. Winsock RemoteHost IP Address
    Hi I am using Winsock and specifying the RemoteHost as a network name. How do I specify this using an IP address though? TcpClient.RemoteHost = "WEBDEV" is what I have at the moment. Cheers Dave

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: mcriderPosted on 1999-09-13 at 17:00:01ID: 2043812

Are you using a machine name only or are you using a URL?

If you are using a machine name only, are they defined in the \WINDOWS\HOSTS file?

Depending on what you are doing, you may want to use the OpenURL or Execute methods.

 

by: bubblesPosted on 1999-09-13 at 19:03:57ID: 2043952

I am only using machine names at the moment. I do not have anything defined in the hosts.sam file, because I am not using DNS. For the sake of simplicity, lets just say that I am making a chat program like winpopup. I am using the UDP protocol that is available with the winsock control.

VB Books Online come with some sample programs of how to make a simple Peer to Peer chat program with the winsock control. According to the examples, you should be able to just use machine names. I can't. Has anyone else tried this?

 

by: jimlamPosted on 1999-09-13 at 23:54:43ID: 2044353

As mentioned by mcrider, you need to either use DNS, WINS or the HOSTS file. All this different method provides is a way to translate a name into an IP address. And for your home network, I would say DNS and WINS is an overkill.

Easiest way is to use the HOSTS file, create a HOSTS file, using the HOSTS.SAM as an example, put in your IP address and machine name separated by tabs. And put it in every PC that you got in your home.

Good luck,
Jim


 

by: RayDeweyPosted on 1999-09-14 at 00:02:19ID: 2044364

Here's how I do it:

Private Type wsadata_type  ' returned by the WSAstartup call
    wVersion As Integer
    wHighVersion As Integer
    szDescription As String * 257
    szSystemStatus As String * 129
    iMaxSockets As Integer
    iMaxUdpDg As Integer
    lpVendorInfo As Long
End Type

Private Declare Function WSAstartup Lib "wsock32.dll" Alias "WSAStartup" _
        (ByVal wVersionRequired As Long, _
         lpWSAData As wsadata_type) _
         As Long
Private Declare Function WSACleanup Lib "wsock32.dll" () _
         As Long
Private Declare Function gethostbyname Lib "wsock32.dll" _
        (ByVal hostname As String) _
         As Long
Private Declare Function WSAGetLastError Lib "wsock32.dll" () _
         As Long
Private Declare Sub CopyMemoryToArray Lib "kernel32" Alias "RtlMoveMemory" _
        (destarray As Any, _
         ByVal src As Long, _
         ByVal bytes As Long)

Private Function GetIPAddress _
 (ByVal sComputerName As String) _
  As String
Dim wsadata As wsadata_type
Dim hostent(0 To 3) As Long
Dim IPptr(0) As Long
Dim IPaddr(0 To 3) As Byte
Dim nRet As Long
Dim hn As String * 128
Dim i As Integer
Dim s As String

    If WSAstartup(0&, wsadata) < 1& _
     Then Err.Raise WSAGetLastError(), "", _
     "Error getting IP Address."
    hn = sComputerName & Chr$(0)  ' null-terminate
    nRet = gethostbyname(hn)
    If nRet <> 0& Then
        ' returned address of a hostent structure
        ' copy structure from winsock memory
        Call CopyMemoryToArray(hostent(0), nRet, 16)
        ' copy pointer into IPptr variable
        Call CopyMemoryToArray(IPptr(0), hostent(3), 4)
        ' copy first IP address
        Call CopyMemoryToArray(IPaddr(0), IPptr(0), 4)
        For i = 0 To 3
            s = s & IPaddr(i)
            If i < 3 Then s = s & "."
        Next i
        GetIPAddress = s
    End If
    WSACleanup
End Function

 

by: bubblesPosted on 1999-09-14 at 14:47:43ID: 2046697

I already do it this way, and so your answer doesn't really help.

What I'd really like to know is, can I get away with not assigning IP addresses? The documentation with the Winsock control gives me the impression that I shouldn't have to have IP addresses asssigned to a machine, but that instead I can just supply a machine name to the winsock control. It's a real nusaince having to have IP addresses, because if somone wants to use my program with a dial-up adapter, they have to assign an IP address to their machine, and then remove it so they can connect to the net. Any words of wisdom would be appreciated!

 

by: wokaPosted on 1999-09-14 at 15:36:05ID: 2046866

If you had a letter to send, but didn't know the address, and had knowone to ask (like our good friend DNS), how do you think the letter would be delivered ?

Even when you use a machine name, it has to be converted to an IP address, as someone said earlier, the easiest way is to use the hosts file, but you have to assign an IP address.  This shouldn't interupt your dial-up connection because (presumably) your assigning the IPS address to your network adaptor, not the dial-up adaptor.

 

by: mcriderPosted on 1999-09-14 at 16:35:18ID: 2046958

if you want to connect by machine name instead of IP address, you must put an entry in your C:\windows\hosts file that equates the name with an IP address.  Unless you're getting the machine name resolved from a DNS server, this is the only way to use winsock the way you described it.

The winsock widget is used for IP communications and for it to make a connection, it must "eventually" get an IP address to start the connection. It gets that IP address by one of the following methods:

1) You directly supply an IP address.

2) You supply a machine name and the windows resolver gets the IP address from the definition in the C:\windows\hosts file.

3) You supply a machine name and the windows resolver contacts a DNS server for the IP address.

There is no other way.

 

by: bubblesPosted on 1999-09-14 at 20:19:31ID: 2047236

In regard to woka's comments, I'd like to say one or two things.

* How do you think mailslots work? In WinPopup, you give a machine name, and it will deliver the message to the machine. Obviously the message gets sent to all computers, and the one with the appropriate name opens it. I had the idea the Winsock might use a similar method. Obviosuly I was wrong!

* You are right about an IP address not affecting dial-up because it is assigned to the network adapter, but what if my program is used on a machine where there is only a dial-up adapter? That is the problem.

I'll accept the answer here, because I have obviously run into a dead end. Thanks everyone.

 

by: wokaPosted on 1999-09-15 at 05:54:37ID: 2048265

Create two different dial-up profiles, one with an IP address (to use at home) and one without (for your ISP).  Then use the hosts table to enable the use of names.

 

by: bubblesPosted on 1999-09-15 at 12:34:58ID: 2049442

That doesn't work. I've tried it.

 

by: mcriderPosted on 1999-09-15 at 12:55:47ID: 2049494

If your program is running on a system with a dial-up only, then it has to dial into something to connect and send your information, right?

It will connect to a service provider and the service provider will assign a dynamic IP address.  With very few exceptions, you get a different IP address assigned every time you log on.

In this case you will have to have a server program running somewhere that is accessable to everyone using your program so your program can "announce" to the server that your program is running and what the dynamic IP address is.

When I do things like this, I use a web cgi program to keep track of connections... It goes like this in 7 simple steps...


1) Web CGI is always waiting for a connection.

2) User runs your program... it connects to the webserver on port 80 using the winsock DLL and announces its IP address to the server.  You can get your assigned IP address from the winsock DLL.

3) The Web CGI stores the announcement on the webserver and then broadcasts the IP address of everyone else that has announced themselves.

4) On a timer, your program optionally re-checks the webserver to see if new IP addresses have been announced.

5) You do your "program thing"

6) You announce to the webserver that your program is terminating, and it removes your IP address from it's broadcast list.

7) Your program terminates.



Simple huh?

 

by: wokaPosted on 1999-09-15 at 15:37:01ID: 2049961

It does work.  I'm doing it right now.  I have my ISP's profile, and one to dial into a PC running DUN Server.  Not all that easy to get it going I must admit, and I can't remember the steps to reproduce, but if you just keep changing things it works eventually !!

On the one with a hard coded IP, server types window has:

Log onto Network, Enable Software Compression and all 3 protocols checked.  All others are unchecked.  In TCP/IP settings, I've specified an IPS address, NOT specified a any DNS servers and have header compression and default gateway checked (what gateway ?!, still it works).

On my ISP profile, only Enable Software Compression and TCP/IP are checked in the server types window.  Under TCP/IP settings I have a server assigned IPS address, specified a primary and seconday DNS and have header compression and default gateway checked.

Both profiles use PPP.

 

by: RayDeweyPosted on 1999-09-16 at 00:02:34ID: 2050616

Well, bubbles, after re-reading your original question, it seems to me that you have written a custom application that has to work only on your three local networked computers.  If that is the case, then why insist that the WinSock control has to work with a computer name?  Why not just set up a lookup table in your software with the three IP addresses, so you can refer to them by computer names or by any other designation you might wish to use?

Advice: Curt dismissals of genuine attempts to assist you as "not useful" don't inspire further offers of help.

 

by: mcriderPosted on 1999-09-16 at 08:30:01ID: 2051734

Here's another option for you if you are only using 3 local systems. drop winsock completely and set up Network Neighborhood "Shared directories" on all 3 systems.

Then you can setup communications through the filesystem.
If for example you have 3 systems called Larry, Moe, and Curly you can set a shared directory on each system in C:\DATA.

Your program can use VB file open to communicate by opening the paths  "\\Larry\Data\com_file.txt", "\\Moe\Data\com_file.txt", "\\Curly\Data\com_file.txt".

Your program can communicate this way to your hearts content. If you are going to go this way, I suggest reading up on pipe files.

-----------------------------------------------
Need to search EE?
Goto http://www.caas.com/html/downloads.shtml

 

by: bubblesPosted on 1999-09-16 at 17:01:34ID: 2052943

In response to the comments:

RayDewey: My custom app is currently working with our three home computers. However, when it is completed I hope that it will be useful on any network, not just ours. I am not insisting that I must pass computer names to the Winsock control. In fact, I have had a lookup table like you described set up from the start. I was hoping I could forget about IP addresses and make my program easier to use and understand. I would like it so that I don't even have to setup any Network proocols either. Obivously, dreams are free. As for your advise on 'curt dissmissals'. While they may appear that way, maybe not everyone has as much time as you. I wouldn't take it personally. When I write things like that, I am usually in a hurry. My apologies if my comments appear unfriendly.

Mcrider: I have thought about that option, and also mailslots. However, I need security and I don't want my app to write to a disk at all - whether temp files or pipe files. If anyone knows of another method of peear to peer communication that is reasonably fast, secure, does not need to write to disk and will work over any network (dial-up or fixed) I'd be interested to hear what it is! I just figured Winsock does this best. Once again, I could be wrong.

Anyway. I appreaciate the way you guys stick at these questions. Thanks a lot.

 

by: mcriderPosted on 1999-09-16 at 17:24:47ID: 2052963

Ok, One last thought, Add a registration server to your program. Your user's program would be configured with the name/IP address of the registration program.

The registration server would have a fixed IP Address.

PCs broadcast their IP addresses to the registration server, in return, the registration server would send the IP addresses of all the currently registered systems.

When the User wants to stop the program, the program contacts the registration server and tells it to remove it's IP address from the "currently active list", and tells all of the systems that it is connected to that it is leaving the group.

 

by: MoondancerPosted on 2002-03-14 at 20:10:43ID: 6867170

This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...