|
|
|
|
![]() ![]() |
Dec 30 2005, 12:07 PM
Post
#1
|
|
|
Premium Member Group: Members Posts: 209 Joined: 7-October 05 From: Đà Nẵng City - Việt Nam Member No.: 8,966 |
I used to use the WinSock control in the traditional VB6 to make connections between computers. But now, I've moved to VB.NET and I want to know how can I do the same thing in .NET. Is there any .NET class that have the same function as WinSock 2? Please help me, I may need some example on how to use that class (code in VB.NET, please).
This post has been edited by miCRoSCoPiC^eaRthLinG: Dec 30 2005, 02:12 PM |
|
|
|
Dec 30 2005, 02:10 PM
Post
#2
|
|
|
PsYcheDeLiC dR3aMeR Group: Admin Posts: 2,242 Joined: 29-January 05 From: Nakorn Chaisri, Thailand Member No.: 2,411 myCENTs:84.36 |
The days of nasty API Calls and Winsock are long over - VB.NET provides you with a bunch of prebuilt classes under System.Net namespace, and socket related functions can be accessed under System.Net.Sockets. Your best reading in this regard will come from the MSDN libraries which contain plenty of good examples to get you started with the new design model.. You should use the VS.NET Object Browser to study the class structure under these two namespaces and then refer to the MSDN Lib. for documentation on each individual function/class.
Some quick references: 1. http://www.eggheadcafe.com/articles/20020323.asp 2. http://www.vbcity.com/forums/faq.asp?fid=15&cat=Winsock 3. http://www.vbip.com/whatsnew.asp 4. http://www.codeproject.com/vb/net/winsockdotnet.asp |
|
|
|
Dec 30 2005, 11:14 PM
Post
#3
|
|
|
Premium Member Group: Members Posts: 209 Joined: 7-October 05 From: Đà Nẵng City - Việt Nam Member No.: 8,966 |
Everything's doing well. I've checked out the MSDN Lib, they have detailed information and articles about this. I can start my project now.
Thanks for references. |
|
|
|
Jan 8 2006, 05:19 AM
Post
#4
|
|
|
Super Member Group: [HOSTED] Posts: 557 Joined: 25-April 05 Member No.: 4,374 myCENTs:17.04 |
PureHeart,
Do you have any specific needs reguarding sockets? I have written quite a few programs using the system.net functions and maybe I could give you a start. Do you need two programs to communicate or something different? BTW does anone know if 2005 added a timeout to the HttpWebRequest initial request? I know there is a timeout that you can specify for already opened connections (httpRequest.Timeout) but not for the initial request. I look and pulled many a hair out till I found that it just simply could not be done in 2003. It always defaults to some predetermined value (21 seconds I believe). While I am on the subject, here is some code that just about all beginners need when messing around with system.net. This code connects to a specified website and returns the HTML. CODE Try
httpRequest = CType(WebRequest.Create(“http://www.google.com”), _HttpWebRequest) ‘set theconnection timeout to 10 seconds httpRequest.Timeout = 10000 ‘change some of the headers so it makes the program look ‘like it cam from IE 6.0 httpRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, _image/pjpeg, application/x-shockwave-flash, application/vnd.ms _excel, application/vnd.ms-powerpoint, application/msword, */*" httpRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows _NT 5.1; SV1; .NET CLR 1.1.4322)" httpResponse = CType(httpRequest.GetResponse(), HttpWebResponse) responseStream = httpResponse.GetResponseStream() responseEncoding = System.Text.Encoding.GetEncoding("utf-8") responseStreamReader = New StreamReader(responseStream, _responseEncoding) ‘This is the HTML string ‘Should put more error handling here, you will need it dim strResponse as string = responseStreamReader.ReadToEnd Catch ex As WebException MessageBox.Show(ex.Status.ToString) Catch ex As System.InvalidOperationException MessageBox.Show(ex.Status.ToString) End Try |
|
|
|
Jan 8 2006, 05:34 AM
Post
#5
|
|
|
Premium Member Group: Members Posts: 209 Joined: 7-October 05 From: Đà Nẵng City - Việt Nam Member No.: 8,966 |
QUOTE(tansqrx @ Jan 8 2006, 12:19 PM) PureHeart, Do you have any specific needs reguarding sockets? I have written quite a few programs using the system.net functions and maybe I could give you a start. Do you need two programs to communicate or something different? BTW does anone know if 2005 added a timeout to the HttpWebRequest initial request? I know there is a timeout that you can specify for already opened connections (httpRequest.Timeout) but not for the initial request. I look and pulled many a hair out till I found that it just simply could not be done in 2003. It always defaults to some predetermined value (21 seconds I believe). There're two different part in my Application. One for server and one for client. The clients connect to the server and send command (as text), graphic(bitmap), mutimedia. I need to make communication between the server and clients. The app only open one connection for each client. So, I need to detect which kind of data is being transfer. Well, you have written programs using system.net . I would be very happy if you send me your code (just for reference). My email address is thepureheart@gmail.com |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 4th December 2008 - 03:07 AM |