文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>winsock

winsock

时间:2008-10-21  来源:splendour

Records 1-1 of 1
   Software Name  /  Popularity  Revised  Size  License  
OstroSoft Winsock Component
COM library for Visual Basic 6, providing an easy access to the network layer of operating system (UDP and TCP sockets). OSWINSCK.dll serves as a wrapper for Winsock API and helps programmers to abstract from complexity of API calls and concentrate on application functionality.

http://www.ab-archive.com/files/oswinsck.html

下载示例代码
VB

http://www.tek-tips.com/viewthread.cfm?qid=938038

Is it possible to use Winsock with a script to send a command to a remote host? I've been searching around on the web and it is very hard to find information on how to do this. I've found some sample code, but I don't know what kind of commands I can call on this winsock object (ie. what is the api?).

My goal is to have a client script to:
1) connect to the remote host
2) send a command... this will cause the remote host to run a command which takes approximately 5 minutes to complete.
3) capture any data sent back to the client and write to a file
4) client detects that server operation is done
5) client disconnects

is this possible with a script? or do I have to use something like VB? This is to be part of an automated process so I don't want to require any gui or user input.

Thanks in advance,
Beth

Here is some sample code that I found:

CODE:
[Copy to clipboard]
set winsock = createobject("MSWINSOCK.Winsock")
winsock.Remotehost = "127.0.0.1"
winsock.RemotePort = 695 --------------------------------------------------------------------------------------------------------------------------------

It is indeed possible to do this.  There are limitations however.  Since the Winsock control is a "licensed control" one must pass a runtime license to the script host.

This works fine for an HTA or even an HTML page, because there is a special IE mechanism for doing it.

WSH has no such facility however.  This means that such a script, whether WScript or CScript, will only run on machines that have a developer license installed, usually by installing Visual Studio or VB.

Don't give up though.  I have had excellent luck employing the free Dimac w3Sockets component.  Go to Dimac, select w3Sockets from the list in the left nav-area of the page under Free Products.

While designed for use from an ASP page, it works great in a .vbs or .wsf file.  You didn't say what the remote server type is.  w3Sockets supports Telnet as well as bare TCP sockets though.  If you need to talk to an HTTP server, you'll need to send the HTTP protocol manually over a bare socket.  But the Winsock control would leave you with that issue anyway.

I'm making the assumption that you want a blocking socket.  w3Sockets can only operate in this fashion.  For simple applications this is a boon.  The Winsock control can't do this, and you must write event-handling logic to deal with its async nature.

I'm sure there are other free alternatives as well.  I use this one because I need to deal with Telnet off and on, and contrary to a lot of sample code, Telnet <> TCP.  Most Telnet servers will spew a lot of Telnet option negotiation sequences and such (and expect same back).  w3Sockets can (optionally) deal with this for you "behind the scenes."

Trivial sample, dimac.wsf:

CODE:
[Copy to clipboard]
<job>
  <object id="w3sock" progid="socket.tcp" />
  
</job> Here I tell w3Sockets I want to do Telnet, terminal type "TTY" (dumb as possible), and I log on.

Then I set the Windows Telnet server's command prompt to <READY> (by using $LREADY$G) because there will be > symbols in the text I want to capture.

Then I send a dir command, and wait for the command prompt to tell me I have it all. Then I grab the results from the buffer and display it.

If you prefer to write old-style .vbs files, you'll need something like:

CODE:
[Copy to clipboard]
Dim w3sock
Set w3sock = CreateObject("socket.tcp")
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载