Thread obsoleto winsock per inviare comandi

Damiano Dotto

Utente Master
Autore del topic
7 Maggio 2009
2.275
60
Miglior risposta
0
il titolo mi sa che dice tutto......cmq io vorrei creare un programma client e server ....la connessione riesco a farla.... e anke inviare text dal client al server ma i comandi come apri il lettore cd .... non ci riesco......aiutatemi perfavore ( grazie in anticipo)...:pianto:
 
xD al client nel button inserisci,
Case "Apricd"
e nel server nel winsock inserisci
Case "Apricd"
retvalue = mciSendString("set CDAudio door open", returnstring, 127, 0)

questo è quello ke devi inserire poi devi inserire all'inizio mi sembra case quelkosa del genere... spero di essere stato utile
 
'Questo server per aprire e chiudere
Option Explicit
Private Declare Function mciSendString Lib "winmm.dll" Alias _
"mciSendStringA" (ByVal lpstrCommand As String, ByVal _
lpstrReturnString As String, ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) As Long
Dim returnstring As Long, retvalue As Long
'---------------------------------------------------------------
Private Sub Command1_Click()

'Apre il CD
retvalue = mciSendString("set CDAudio door open", _
returnstring, 127, 0)

End Sub
'---------------------------------------------------------------
Private Sub Command2_Click()

'Chiude il CD
retvalue = mciSendString("set CDAudio door closed", _
returnstring, 127, 0)

End Sub

'questo e il client

Private Sub Form_Load()
Dim Data As String
Dim Text As String
End Sub

Private Sub Command1_Click()
Winsock1.Close
Winsock1.Connect Text1.Text, Text2.Text
End Sub


Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Winsock Error!" & Err.Description, vbCritical

End Sub

Private Sub Winsock1_Connect()
MsgBox "Connesso!"
End Sub

'e questo e il comando che devi inviare al server

winsock1.senddata "apricd"


server

'formload

Winsock1.Listen

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> 0 Then Winsock1.Close
Winsock1.Accept requestID
End Sub

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

Winsock1.GetData dati
Select Case dati
case "apricd"
timer1.enabled = true
end select
end sub

'inserire timer ed dentro ci inserisci

retvalue = mciSendString("set CDAudio door open", _
returnstring, 127, 0)
timer1.enabled = false

'ritorna al form load
inserisci

Option Explicit
Private Declare Function mciSendString Lib "winmm.dll" Alias _
"mciSendStringA" (ByVal lpstrCommand As String, ByVal _
lpstrReturnString As String, ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) As Long
Dim returnstring As Long, retvalue As Long

'ultimo imposta il timer su interval = 100


Spero ti sia stato utile
-xkaos17-
 
'Questo server per aprire e chiudere
Option Explicit
Private Declare Function mciSendString Lib "winmm.dll" Alias _
"mciSendStringA" (ByVal lpstrCommand As String, ByVal _
lpstrReturnString As String, ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) As Long
Dim returnstring As Long, retvalue As Long
'---------------------------------------------------------------
Private Sub Command1_Click()

'Apre il CD
retvalue = mciSendString("set CDAudio door open", _
returnstring, 127, 0)

End Sub
'---------------------------------------------------------------
Private Sub Command2_Click()

'Chiude il CD
retvalue = mciSendString("set CDAudio door closed", _
returnstring, 127, 0)

End Sub

'questo e il client

Private Sub Form_Load()
Dim Data As String
Dim Text As String
End Sub

Private Sub Command1_Click()
Winsock1.Close
Winsock1.Connect Text1.Text, Text2.Text
End Sub


Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Winsock Error!" & Err.Description, vbCritical

End Sub

Private Sub Winsock1_Connect()
MsgBox "Connesso!"
End Sub

'e questo e il comando che devi inviare al server

winsock1.senddata "apricd"


server

'formload

Winsock1.Listen

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> 0 Then Winsock1.Close
Winsock1.Accept requestID
End Sub

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

Winsock1.GetData dati
Select Case dati
case "apricd"
timer1.enabled = true
end select
end sub

'inserire timer ed dentro ci inserisci

retvalue = mciSendString("set CDAudio door open", _
returnstring, 127, 0)
timer1.enabled = false

'ritorna al form load
inserisci

Option Explicit
Private Declare Function mciSendString Lib "winmm.dll" Alias _
"mciSendStringA" (ByVal lpstrCommand As String, ByVal _
lpstrReturnString As String, ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) As Long
Dim returnstring As Long, retvalue As Long

'ultimo imposta il timer su interval = 100


Spero ti sia stato utile
-xkaos17-

Scusa se lo fa in vb8 nn funziona