Results 1 to 10 of 10

Thread: Winsock Control?? [Resolved]

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    5

    Winsock Control?? [Resolved]

    Hi all.
    I know this is probably a newbie question, but I have searched this forum, as well as googled it, and I cannot find exactly what I am looking for.

    I am using VB.NET 2003. I am wanting to make a client/server application (right now a chat program, so I can get used to how it works)

    In most examples I have found, they use Sock.Whatever or Winsock.whatever.

    I notice no dims in the code that I have downloaded. I can only assume that it is a control that you put on the form, or that it is a dim that I missed.

    Will someone please tell me what the dim command is for windows sockets, such as dim Sock as WinSocket.

    If not, PLEASE tell me where I can find the winsock control. I searched EVERYWHERE in my Visual Studio 2003 and could not find the control.

    Thanks for all your help!
    Last edited by mourgent; Oct 15th, 2004 at 09:33 AM.

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    If you're going to do socket stuff, I guess you can use the Winsock control, but you can also use .NET classes. If you want to do it the .NET way, check out the topics in MSDN titled "Using a Synchronous Server Socket", "Using a Synchronous Client Socket". Also see the example topics, and if you want to be really cool, the asynchronous counterparts.

    If you want to use the Winsock control, you have to add it to your workspace. That's why you don't see it in the default setup. Right click in your toolbox (ctrl-alt-x) choose "Add/Remove Items...", click on the "COM Components" tab, scroll down to "Microsoft Winsock Control, version 6.0 (SP6)" (or whatever version you have), click "OK" and you have the ActiveX control in your toolbox. Notice that some references have been added as well.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    5

    Thanks

    Thanks
    Ill look into the other way you told me. I never knew you could do it that way (Im just coding this stuff to learn)

    Also. I added the winsock control as above and it says that I do not have a license to use that control....
    How do I get a license to use it?
    BTW Im using the Academic version of Studio.NEt (free from school)

    What is the advantage of doing it the .NET way instead of using windows sockets?

    Thanks!
    Last edited by mourgent; Oct 14th, 2004 at 08:21 PM.

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Sorry, I'm not sure about the licensing business. I've used the Winsock control in VB6, but never in a .NET project.
    What is the advantage of doing it the .NET way instead of using windows sockets?
    You're still using windows sockets, just not the Winsock control. Instead you use .NET classes. I guess the advantage would be just that.

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    5

    Ok...

    Alright. I looked over the examples at MSDN. The only problem I have is that is still geared a more experienced programmer. I assume that those classes are librarys that come with VB.net? (Sorry Im a C++ guy learning VB)

    So I guess what im asking is I need to include those classes somewhere or declare them.

    In c++ id do a #include<whatever>

    Do I just dim a variable as something or what?

    Thanks for being patient with me.

  6. #6
    Junior Member
    Join Date
    Jul 2004
    Posts
    29
    Include in c++ is the same as Imports in VB.
    Example:
    Imports System.Net.Sockets

    So for a socket you e.g. for the serverside do:

    VB Code:
    1. dim port as int32 = 1099 'select the port you want...
    2. Dim tcpListener As New TcpListener(Net.IPAddress.Any, port)
    3.  
    4. tcpListener.Start()
    5.  
    6. If tcpListener.Pending Then
    7. Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient
    8.  
    9. 'do the communication here using the network stream
    10.  
    11. tcpClient.Close()
    12. end if
    13. tcpListener.Stop()

    The advantage over winsock is, that it's less code

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    5

    Ok thanks!

    Alright thanks.

    So I assume I put Imports System.Net.Sockets in my general declerations? I put it in a program I had and it threw a code. Said it was a namespace and as such is not a valid expression. Is there a namespace command i need to change?



    Thanks again!
    Last edited by mourgent; Oct 15th, 2004 at 09:22 AM.

  8. #8
    Junior Member
    Join Date
    Jul 2004
    Posts
    29
    When you open a the code module of a form/class, your code could start like this:

    VB Code:
    1. Option Explicit On
    2.  
    3. Imports System
    4. Imports System.IO
    5. Imports System.Net.Sockets
    6.  
    7. Public Class XYZ
    8. '....

    If you mean that with general declarations, then yes

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    5

    Thanks!

    Thanks! that got it fixed.


    Btw I assume option explicit is like using namespace std; right?

    Keep your eyes open! Im sure Ill be back in the next few days with another question about this stuff!

  10. #10
    Junior Member
    Join Date
    Jul 2004
    Posts
    29
    option explicit forces you to use the "dim" statement when declaring variables and should always be turned on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width