Important alert: (current site time 7/15/2013 10:58:13 PM EDT)
 

VB icon

A client server network sample, based on Winsock

Email
Submitted on: 5/12/2004 10:34:35 AM
By: Tako Griffith 
Level: Beginner
User Rating: Unrated
Compatibility: ASP (Active Server Pages), HTML, VbScript (browser/client side)
Views: 18670
 
     TCP/IP and Winsock based client server sample. Client connects to server (listens on port 1500) and sends a couple of messages.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: A client server network sample, based on Winsock
' Description:TCP/IP and Winsock based client server sample. Client connects to server (listens on port 1500) and sends a couple of messages.
' By: Tako Griffith
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=8837&lngWId=4'for details.'**************************************

' ********************************************************************
' TCP/IP client/server sample - send and Receive binary data
'Requires freeware ASocket.dll to run the sample.
'Download it from http://www.vahland.com/asocket/asocket.dll
'and register it (REGSVR32 asocket.dll) on your machine.
'
' IMPORTANT: 
'Online manual: http://www.vahland.com/asocket/manual.htm
' ********************************************************************
' Constants: Connection states
Const asCONN_DISCONNECTED=1
Const asCONN_LISTENING=2
Const asCONN_CONNECTED=3
' Constants: Error codes
Const asERR_SUCCESS=0
' Constants: Protocols
Const asPROTOCOL_RAW=1
Const asPROTOCOL_TELNET=2
' Create a socket instance
Set asObj = CreateObject("ActiveXperts.Socket")
asObj.Protocol = asPROTOCOL_RAW
' Make a connection to port 1500 on remote server
asObj.Connect "127.0.0.1", 1500
WScript.Echo "Connect: result = " & asObj.LastError
If asObj.LastError = 11001 Then
WScript.Echo "Error 11001: Specify a valid hostname-parameter in the Connect-method."
End If
If asObj.LastError = asERR_SUCCESS Then
 ' YES, we established a connection
 WScript.Echo "Connection established" & vbCrLf
 ' Send 256 bytes now: 0, 1, .., 255
 For i = 0 To 255
asObj.PutByte( i )
WScript.Echo "PutByte: " & i
If i mod 10 = 0 Then
 asObj.SendBytes()
 WScript.Echo "SendBytes, result: " & asObj.LastError
 asObj.Sleep 1000
End If 
 Next
 asObj.SendBytes()
 WScript.Echo "SendBytes, result: " & asObj.LastError
 ' And finally, disconnect
 asObj.Disconnect
End If


Other 5 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
5/25/2005 9:53:09 AMleo

Why do you say the asocket.dll is freeware? It is SHAREWARE, NOT freeware

Leo

Free the code !!!

(If this comment was disrespectful, please report it.)

 
2/21/2008 9:31:51 PMSnobDuck

Yeah!!!
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.