Deutsches AutoHotkey Homepage AutoHotkey Community
Wir helfen uns gegenseitig aus der Patsche
 
 FAQFAQ   SuchenSuchen   MitgliederlisteMitgliederliste   RegistrierenRegistrieren 
 ProfilProfil   Einloggen, um private Nachrichten zu lesenEinloggen, um private Nachrichten zu lesen   LoginLogin 

Remote Player (Server/Client)

 
Neues Thema eröffnen   Neue Antwort erstellen    AutoHotkey Community Foren-Übersicht -> Skripte & Funktionen
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen  
Autor Nachricht
Ripp3r]D3[



Anmeldedatum: 11.11.2007
Beiträge: 411
Wohnort: Altenburg\Kernel32.dll

BeitragVerfasst am: So März 23, 2008 2:31 pm    Titel: Remote Player (Server/Client) Antworten mit Zitat

Wieder mal ein Mini Player den man fern steuern kann...
denick wenn du lust hast kannsten ja wieder ausbauen Laughing Wink
@Bobo
Dafür habe ich das gebraucht ...net immer das schlimmste denken
Wink Wink
Das script baut auf die vorgabe von Zed Gecko auf.
http://www.autohotkey.com/forum/topic13829.html


Server:

Code:

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
Gui, Add, GroupBox, x6 y10 w350 h160 , Remote-Player-Server
Gui, Add, Text, x16 y30 w100 h20 , Server-IP
Gui, Add, Edit, x126 y30 w100 h20 vIP, 0.0.0.0
Gui, Add, Text, x16 y60 w100 h20 , Server-Port
Gui, Add, Edit, x126 y60 w100 h20 vPort, 8080
Gui, Add, Button, x236 y30 w100 h50 gStartServer, Start-Server
Gui, Add, Button, x16 y90 w100 h30 gPlay, Play
Gui, Add, Button, x126 y90 w100 h30 gNext, Next
Gui, Add, Button, x16 y130 w100 h30 gStop, Stop
Gui, Add, Button, x126 y130 w100 h30 gPrev,Preview
Gui, Add, Button, x16 y180 w100 h30 gGuiClose, Exit
Gui, Add, Button, x126 y180 w100 h30 gAbout, About
Gui, Add, Edit, x236 y180 w120 h30 , Remote-Player`nCoded by Ripp3r]D3[
Gui, Show, x296 y91 h217 w368,  Remote-Player-Server
Return

Play:
Data=Play
goto,SendviaNet
return


Stop:
Data=Stop
goto,SendviaNet
return

Next:
Data=Next
goto,SendviaNet
return

Prev:
Data=Prev
goto,SendviaNet
return


About:
return


StartServer:
MsgBox,Server Started
; -------------------------------------------------
; ------------SERVERSCRIPT------------------
; -------------------------------------------------
;-------thx2 Zed Gecko------------------------
; CONFIGURATION SECTION:
; Specify Your own Network's address and port.
GuiControlGet,IP,,IP
GuiControlGet,Port,,Port
Network_Address = %IP%
Network_Port = %Port%
; ----------------------------
; END OF CONFIGURATION SECTION
; ----------------------------


Gosub Connection_Init
return

Connection_Init:
OnExit, ExitSub  ; For connection cleanup purposes.

; set up a very basic server:
socket := PrepareForIncomingConnection(Network_Address, Network_Port)
if socket = -1  ; Connection failed (it already displayed the reason).
    ExitApp

; Find this script's main window:
Process, Exist  ; This sets ErrorLevel to this script's PID (it's done this way to support compiled scripts).
DetectHiddenWindows On
ScriptMainWindowId := WinExist("ahk_class AutoHotkey ahk_pid " . ErrorLevel)
DetectHiddenWindows Off

; Set up the connection to notify this script via message whenever new data has arrived.
; This avoids the need to poll the connection and thus cuts down on resource usage.
FD_READ = 1     ; Received when data is available to be read.
;FD_WRITE =
FD_CLOSE = 32   ; Received when connection has been closed.
FD_CONNECT = 20 ; Received when connection has been made.
if DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, "UInt", ScriptMainWindowId, "UInt", NotificationMsg, "Int", FD_CLOSE|FD_CONNECT)
{
    MsgBox % "WSAAsyncSelect() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
    ExitApp
}

Loop ; Wait for incomming connections
{
; accept requests that are in the pipeline of the socket   
   conectioncheck := DllCall("Ws2_32\accept", "UInt", socket, "UInt", &SocketAddress, "Int", SizeOfSocketAddress)
; Ws2_22/accept returns the new Connection-Socket if a connection request was in the pipeline
; on failure it returns an negative value
    if conectioncheck > 1
    {
       MsgBox Incoming connection accepted
       break   
   }
    sleep 500 ; wait half 1 second then accept again
}   
return

SendviaNet:
SendText=%Data%
Gui, Submit, NoHide
SendData(conectioncheck,SendText,Repeat,Delay)
return

PrepareForIncomingConnection(IPAddress, Port)
; This can connect to most types of TCP servers, not just Network.
; Returns -1 (INVALID_SOCKET) upon failure or the socket ID upon success.
{
    VarSetCapacity(wsaData, 32)  ; The struct is only about 14 in size, so 32 is conservative.
    result := DllCall("Ws2_32\WSAStartup", "UShort", 0x0002, "UInt", &wsaData) ; Request Winsock 2.0 (0x0002)
    ; Since WSAStartup() will likely be the first Winsock function called by this script,
    ; check ErrorLevel to see if the OS has Winsock 2.0 available:
    if ErrorLevel
    {
        MsgBox WSAStartup() could not be called due to error %ErrorLevel%. Winsock 2.0 or higher is required.
        return -1
    }
    if result  ; Non-zero, which means it failed (most Winsock functions return 0 upon success).
    {
        MsgBox % "WSAStartup() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
        return -1
    }

    AF_INET = 2
    SOCK_STREAM = 1
    IPPROTO_TCP = 6
    socket := DllCall("Ws2_32\socket", "Int", AF_INET, "Int", SOCK_STREAM, "Int", IPPROTO_TCP)
    if socket = -1
    {
        MsgBox % "socket() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
        return -1
    }

    ; Prepare for connection:
    SizeOfSocketAddress = 16
    VarSetCapacity(SocketAddress, SizeOfSocketAddress)
    InsertInteger(2, SocketAddress, 0, AF_INET)   ; sin_family
    InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2)   ; sin_port
    InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), SocketAddress, 4, 4)   ; sin_addr.s_addr

    ; Bind to socket:
    if DllCall("Ws2_32\bind", "UInt", socket, "UInt", &SocketAddress, "Int", SizeOfSocketAddress)
    {
        MsgBox % "bind() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError") . "?"
        return -1
    }
    if DllCall("Ws2_32\listen", "UInt", socket, "UInt", "SOMAXCONN")
    {
        MsgBox % "LISTEN() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError") . "?"
        return -1
    }
   
    return socket  ; Indicate success by returning a valid socket ID rather than -1.
}

SendData(wParam,SendData, Repeat, Delay)
{
   socket := wParam
;   SendDataSize := VarSetCapacity(SendData)
;   SendDataSize += 1

        SendIt := SendData
      SendDataSize := VarSetCapacity(SendIt)
      SendDataSize += 1
     
      sendret := DllCall("Ws2_32\send", "UInt", socket, "Str", SendIt, "Int", SendDatasize, "Int", 0)
      WinsockError := DllCall("Ws2_32\WSAGetLastError")
      if WinsockError <> 0 ; WSAECONNRESET, which happens when Network closes via system shutdown/logoff.
         ; Since it's an unexpected error, report it.  Also exit to avoid infinite loop.
         MsgBox % "Server Down--->send() indicated Winsock error " . WinsockError
   
;send( sockConnected,> welcome, strlen(welcome) + 1, NULL);
}

InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; The caller must ensure that pDest has sufficient capacity.  To preserve any existing contents in pDest,
; only pSize number of bytes starting at pOffset are altered in it.
{
    Loop %pSize%  ; Copy each byte in the integer into the structure as raw binary data.
        DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}

guiclose:
ExitSub:  ; This subroutine is called automatically when the script exits for any reason.
; MSDN: "Any sockets open when WSACleanup is called are reset and automatically
; deallocated as if closesocket was called."
DllCall("Ws2_32\WSACleanup")
ExitApp


Client:

Code:

Gui, Add, ListBox, x6 y10 w310 h230 vPlaylist,
Gui, Add, Button, x326 y10 w100 h30 gFile, Add-File
Gui, Add, Button, x326 y50 w100 h30 gFolder, Add-Folder
Gui, Add, Button, x326 y90 w100 h30 gConnect, Connect2Server
Gui, Add, Text, x326 y130 w100 h20 , Server-IP
Gui, Add, Edit, x326 y160 w100 h20 vIp, 127.0.0.1
Gui, Add, Text, x326 y190 w100 h20 , Port
Gui, Add, Edit, x326 y220 w100 h20 vPort, 8080
Gui, Show, x296 y91 h248 w438, Remote-Player-Client
FileDelete, Playlist.m3u
I=1
Return

File:
FileSelectFile,OneFile
GuiControl,,Playlist,%OneFile%
FileAppend,%OneFile%`n,Playlist.m3u
return

Folder:
FileSelectFolder,Folder
Loop,%Folder%\*.*
   {
    GuiControl,,Playlist,%A_LoopFileFullPath%
    FileAppend,%A_LoopFileFullPath%`n,Playlist.m3u
   }
return


Connect:
MsgBox,Connect!!!
; -------------------------------------------------
;-----------CLIENTSCRIPT----------------------
; -------------------------------------------------
;-------thx2 Zed Gecko------------------------
; CONFIGURATION SECTION:

; Specify address and port of the server.
GuiControlGet,IP,,IP
GuiControlGet,Port,,Port
Network_Address = %IP%
Network_Port = %Port%
; ----------------------------
; END OF CONFIGURATION SECTION
; ----------------------------

LinesReceived:=0
Connection_Init:
OnExit, ExitSub  ; For connection cleanup purposes.

; Connect to any type of server:
socket := ConnectToAddress(Network_Address, Network_Port)
if socket = -1  ; Connection failed (it already displayed the reason).
    ExitApp

; Find this script's main window:
Process, Exist  ; This sets ErrorLevel to this script's PID (it's done this way to support compiled scripts).
DetectHiddenWindows On
ScriptMainWindowId := WinExist("ahk_class AutoHotkey ahk_pid " . ErrorLevel)
DetectHiddenWindows Off

; When the OS notifies the script that there is incoming data waiting to be received,
; the following causes a function to be launched to read the data:
NotificationMsg = 0x5555  ; An arbitrary message number, but should be greater than 0x1000.
OnMessage(NotificationMsg, "ReceiveData")

; Set up the connection to notify this script via message whenever new data has arrived.
; This avoids the need to poll the connection and thus cuts down on resource usage.
FD_READ = 1     ; Received when data is available to be read.
FD_CLOSE = 32   ; Received when connection has been closed.
if DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, "UInt", ScriptMainWindowId, "UInt", NotificationMsg, "Int", FD_READ|FD_CLOSE)
{
goto,Connection_Init
}
return

Clear:
ShowReceived=
LinesReceived:=0   
return

ConnectToAddress(IPAddress, Port)
; Returns -1 (INVALID_SOCKET) upon failure or the socket ID upon success.
{
    VarSetCapacity(wsaData, 32)  ; The struct is only about 14 in size, so 32 is conservative.
    result := DllCall("Ws2_32\WSAStartup", "UShort", 0x0002, "UInt", &wsaData) ; Request Winsock 2.0 (0x0002)
    ; Since WSAStartup() will likely be the first Winsock function called by this script,
    ; check ErrorLevel to see if the OS has Winsock 2.0 available:
    if ErrorLevel
    {
        MsgBox WSAStartup() could not be called due to error %ErrorLevel%. Winsock 2.0 or higher is required.
        return -1
    }
    if result  ; Non-zero, which means it failed (most Winsock functions return 0 upon success).
    {
        MsgBox % "WSAStartup() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
        return -1
    }

    AF_INET = 2
    SOCK_STREAM = 1
    IPPROTO_TCP = 6
    socket := DllCall("Ws2_32\socket", "Int", AF_INET, "Int", SOCK_STREAM, "Int", IPPROTO_TCP)
    if socket = -1
    {
        MsgBox % "socket() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
        return -1
    }

    ; Prepare for connection:
    SizeOfSocketAddress = 16
    VarSetCapacity(SocketAddress, SizeOfSocketAddress)
    InsertInteger(2, SocketAddress, 0, AF_INET)   ; sin_family
    InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2)   ; sin_port
    InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), SocketAddress, 4, 4)   ; sin_addr.s_addr

    ; Attempt connection:
    if DllCall("Ws2_32\connect", "UInt", socket, "UInt", &SocketAddress, "Int", SizeOfSocketAddress)
    {
    goto,Connection_Init
    }
    return socket  ; Indicate success by returning a valid socket ID rather than -1.
}

ReceiveData(wParam, lParam)
; By means of OnMessage(), this function has been set up to be called automatically whenever new data
; arrives on the connection.
{
     Critical
    global ShowReceived
    global MyEdit
    global LinesReceived

    socket := wParam
    ReceivedDataSize = 4096  ; Large in case a lot of data gets buffered due to delay in processing previous data.
    VarSetCapacity(ReceivedData, ReceivedDataSize, 0)  ; 0 for last param terminates string for use with recv().
    Data   := ""
    Loop  ; This loop solves the issue of the notification message being discarded due to thread-already-running.
    {
        ReceivedDataLength := DllCall("Ws2_32\recv", "UInt", socket, "Str", ReceivedData, "Int", ReceivedDataSize, "Int", 0)
        if ReceivedDataLength = 0  ; The connection was gracefully closed,
            ExitApp  ; The OnExit routine will call WSACleanup() for us.
        if ReceivedDataLength = -1
        {
            WinsockError := DllCall("Ws2_32\WSAGetLastError")
            if ( WinsockError = 10035 ) { ; WSAEWOULDBLOCK, which means "no more data to be read".
                break
            }
            if WinsockError <> 10054 ; WSAECONNRESET, which happens when Network closes via system shutdown/logoff.
                ; Since it's an unexpected error, report it.  Also exit to avoid infinite loop.
                MsgBox % "recv() indicated Winsock error " . WinsockError
            ExitApp  ; The OnExit routine will call WSACleanup() for us.
        }
        Data .= ReceivedData
    }
;----------------------------------------------------------
;--------------Received Data-------------------------------
;----------------------------------------------------------
IF (Data="Play")
{
Gosub, Play
}

IF (Data="Stop")
{
Gosub, Stop
}

IF (Data="Prev")
{
Gosub, Prev
}

IF (Data="Next")
{
Gosub, Next
}
;----------------------------------------------------------
;--------------Received Data-------------------------------
;----------------------------------------------------------
    }

InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; The caller must ensure that pDest has sufficient capacity.  To preserve any existing contents in pDest,
; only pSize number of bytes starting at pOffset are altered in it.
{
    Loop %pSize%  ; Copy each byte in the integer into the structure as raw binary data.
        DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}

GuiClose:
ExitSub:  ; This subroutine is called automatically when the script exits for any reason.
; MSDN: "Any sockets open when WSACleanup is called are reset and automatically
; deallocated as if closesocket was called."
MsgBox, 16, Server, Server Down, 3
FileDelete,%A_ScriptDir%\Playlist.m3u
DllCall("Ws2_32\WSACleanup")
exitapp

Play:
FileReadLine,File,%A_ScriptDir%\Playlist.m3u,%I%
SoundPlay,%File%
return

Prev:
I--
if (I<=0)
{
I=1
}
Gosub,Play
Return

Next:
I++
Gosub,Play
Return

Stop:
I=1
SoundPlay,Stop
return

_________________

ResistantX:
"...In deren Köpfen läuft das selbe Programm welches auch bei den früheren Jahrgängen lief! Ich bin der Virus der diese Programme zerstören will..."


Zuletzt bearbeitet von Ripp3r]D3[ am Di März 25, 2008 2:33 pm, insgesamt 2-mal bearbeitet
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden Website dieses Benutzers besuchen
denick



Anmeldedatum: 15.09.2006
Beiträge: 1015
Wohnort: Berlin

BeitragVerfasst am: Di März 25, 2008 6:32 am    Titel: Antworten mit Zitat

Moin,

also hast Du Zed Gecko's Client/Server-Skript schließlich doch gefunden! Wink
_________________
Hilfe zur Hilfe

(de)nick
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden
BoBo¨
Gast





BeitragVerfasst am: Di März 25, 2008 11:09 am    Titel: Antworten mit Zitat

Aufgrund der fehlenden Verweise (auf das Ursprungsskript, weder im Thread, noch im Skript selbst) handelt es sich um ne Lizensverletzung (GPL). Korrigiert mich. Btw, Rippchen ist mein No1 Kandidat für "Nur noch dreimal singen!"

Wie wärs damit Zed Gecko mal ne PM zukommen lassen? Dann darf Rippchen sich mal erklären ...
Nach oben
IsNull



Anmeldedatum: 20.12.2006
Beiträge: 914
Wohnort: CH

BeitragVerfasst am: Di März 25, 2008 1:39 pm    Titel: Antworten mit Zitat

rippchen^^ Mr. Green

btw: Es gibt noch keine standard Lib für Netzwerk/TCP/IP Verbindungen usw. für AHK? Das wäre doch mal ganz nützlich eine gut dokumentierte Lib dazu zu veröffentlichen, auf Basis von zed gecko's script.
_________________

http://securityvision.ch
www.forum.securityvision.ch
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden
Ripp3r]D3[



Anmeldedatum: 11.11.2007
Beiträge: 411
Wohnort: Altenburg\Kernel32.dll

BeitragVerfasst am: Di März 25, 2008 2:35 pm    Titel: Antworten mit Zitat

0k muss ich mal ran setzten Wink
Sry habe ganz vergessen Zed Gecko zu erwähnen ---->EDIT Embarassed Embarassed Embarassed
_________________

ResistantX:
"...In deren Köpfen läuft das selbe Programm welches auch bei den früheren Jahrgängen lief! Ich bin der Virus der diese Programme zerstören will..."
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden Website dieses Benutzers besuchen
Beiträge der letzten Zeit anzeigen:   
Neues Thema eröffnen   Neue Antwort erstellen    AutoHotkey Community Foren-Übersicht -> Skripte & Funktionen Alle Zeiten sind GMT
Seite 1 von 1

 
Gehe zu:  
Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.


Powered by phpBB © 2001, 2005 phpBB Group
Deutsche Übersetzung von phpBB.de