不用Winsock实现程序与单机程序之间的信息通信?

王伟晔 2003-01-10 11:31:55
不用Winsock实现程序与单机程序之间的信息通信?
要即使的
最好也要说一下跨工程的调用!
请说出详细做法!
...全文
4 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
王伟晔 2003-01-28
qqqdong的程序写得很长,非常感谢!
可是误解了我的意思,我要的不是点对点的通信,而是工程与工程之间的通信!interdog的方法是正确的,可是在即时性方面比较难完美。
其实,我想说的就是类似于程序监控器的程序。
例如,把工程1中的计算结果,自动在工程2中的文本框中显示出来。
经过了那么长的日子,时间关系,我的程序还是选用了WINSOCK。
无论怎么样,谢谢各位的帖子。
回复
interdog 2003-01-10
用写文件的方式来实现,各个应用程序之间的通讯,freebsd里面有用到这种方式,
回复
programart_life 2003-01-10
不用套接?你自己写通讯协议?将国际通用的七层网络结构废弃,而采用你自己的结构?呵呵,哈哈,有趣。建议你到微软或者IBM、SUM之类的大公司去从事底层开发吧!~哈哈哈哈
回复
_131_ 2003-01-10
楼主都说了,不用socket的!
这个问题很奇怪,我也想知道怎么实现!

楼主能说明一下为什么不能socket吗?
回复
qqqdong 2003-01-10
一个简单的点对点聊天程序
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form1
Caption = "点对点通讯"
ClientHeight = 6330
ClientLeft = 60
ClientTop = 345
ClientWidth = 6855
Icon = "Form1.frx":0000
LinkTopic = "Form1"
ScaleHeight = 6330
ScaleWidth = 6855
StartUpPosition = 2 'CenterScreen
Begin VB.ListBox lstTo
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 2460
ItemData = "Form1.frx":030A
Left = 90
List = "Form1.frx":030C
TabIndex = 5
TabStop = 0 'False
Top = 3225
Width = 6675
End
Begin MSWinsockLib.Winsock Winsock1
Left = 6345
Top = 2790
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.CommandButton cmdConnect
Caption = "连接"
Height = 495
Left = 4725
TabIndex = 4
TabStop = 0 'False
Top = 2655
Width = 1215
End
Begin VB.TextBox txtIP
Height = 300
Left = 1500
TabIndex = 3
TabStop = 0 'False
Text = "192.168.1.68"
Top = 2760
Visible = 0 'False
Width = 2745
End
Begin VB.CheckBox chkServer
Caption = "服务器"
Height = 330
Left = 120
TabIndex = 2
TabStop = 0 'False
Top = 2745
Visible = 0 'False
Width = 1215
End
Begin VB.TextBox txtMemo
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 360
Left = 75
TabIndex = 1
Top = 5805
Width = 6675
End
Begin VB.ListBox lstFrom
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 2460
ItemData = "Form1.frx":030E
Left = 120
List = "Form1.frx":0310
TabIndex = 0
TabStop = 0 'False
Top = 150
Width = 6615
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub chkServer_Click()
If Me.chkServer.Value Then
If Me.Winsock1.State <> sckClosed Then Me.Winsock1.Close
Me.Winsock1.LocalPort = 4001
Me.Winsock1.Listen
End If
End Sub

Private Sub cmdConnect_Click()
If Me.Winsock1.State <> sckClosed Then Me.Winsock1.Close
Me.Winsock1.RemoteHost = txtIP.Text
Me.Winsock1.RemotePort = 4001
Me.Winsock1.Connect
Call AddTo("呼叫")
End Sub

Private Sub Form_Load()
Call chkServer_Click
End Sub

Public Sub AddTo(ByVal pstrTemp As String)
lstTo.AddItem (pstrTemp)
lstTo.ListIndex = lstTo.ListCount - 1
DoEvents
Me.txtMemo.SetFocus
End Sub

Public Sub AddFrom(ByVal pstrTemp As String)
lstFrom.AddItem (pstrTemp)
lstFrom.ListIndex = lstFrom.ListCount - 1
DoEvents
Me.txtMemo.SetFocus
End Sub

Private Sub lstFrom_DblClick()
Me.lstFrom.Clear
Me.txtMemo.SetFocus
End Sub

Private Sub lstTo_DblClick()
Me.lstTo.Clear
Me.txtMemo.SetFocus
End Sub

Private Sub txtMemo_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
If UCase(Me.txtMemo.Text) = "/SHOW" Then
Me.chkServer.Visible = True
Me.txtIP.Visible = True
Me.txtMemo.Text = ""
Exit Sub
End If
If Len(Trim(Me.txtMemo.Text)) > 0 Then
Call SendInfo(Me.txtMemo.Text)
If Left(Trim(Me.txtMemo.Text), 1) <> "/" Then
Call AddTo(Me.txtMemo.Text)
End If
Me.txtMemo.Text = ""
End If
End If
End Sub

Private Sub Winsock1_Close()
Call chkServer_Click
MsgBox "对方退出"
End Sub

Private Sub Winsock1_Connect()
Call AddFrom("连接成功")
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
With Me.Winsock1
If .State <> sckClosed Then .Close
.Accept (requestID)
DoEvents
'Call SendInfo("连接成功")
Call AddFrom("连接成功")
End With
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strTemp As String

With Me.Winsock1
.GetData strTemp
Select Case UCase(Left(strTemp, 2))
Case "/T"
Me.Caption = Right(strTemp, Len(strTemp) - 2)
Case Else
Call AddFrom(strTemp)
End Select
End With
End Sub

Public Sub SendInfo(ByVal pstr As String)
On Error Resume Next
Me.Winsock1.SendData pstr
End Sub

回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告