|
-
Oct 14th, 2004, 07:18 PM
#1
Thread Starter
New Member
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.
-
Oct 14th, 2004, 07:47 PM
#2
Frenzied Member
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.
-
Oct 14th, 2004, 08:15 PM
#3
Thread Starter
New Member
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.
-
Oct 14th, 2004, 10:06 PM
#4
Frenzied Member
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.
-
Oct 15th, 2004, 12:15 AM
#5
Thread Starter
New Member
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.
-
Oct 15th, 2004, 02:59 AM
#6
Junior Member
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:
dim port as int32 = 1099 'select the port you want...
Dim tcpListener As New TcpListener(Net.IPAddress.Any, port)
tcpListener.Start()
If tcpListener.Pending Then
Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient
'do the communication here using the network stream
tcpClient.Close()
end if
tcpListener.Stop()
The advantage over winsock is, that it's less code
-
Oct 15th, 2004, 09:19 AM
#7
Thread Starter
New Member
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.
-
Oct 15th, 2004, 09:22 AM
#8
Junior Member
When you open a the code module of a form/class, your code could start like this:
VB Code:
Option Explicit On
Imports System
Imports System.IO
Imports System.Net.Sockets
Public Class XYZ
'....
If you mean that with general declarations, then yes
-
Oct 15th, 2004, 09:32 AM
#9
Thread Starter
New Member
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!
-
Oct 15th, 2004, 09:50 AM
#10
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|