AlmarM Posted November 11, 2009 Share Posted November 11, 2009 (edited) Hi,I tried some stuff with the TCP send and receive functions and I cant seem to get it right.What I want is:When the user starts "Client 1.au3" (or Client 2.au3) the scripts takes a screenshot, sends it to the Server.The server will send the screenshot to the other connected client, not the one it received it from.The other connected client has to save the screenshot to the @DesktopDir.Now heres my script:Server.au3#include "TCP.au3" $hServer = _TCP_Server_Create(1337, @IPAddress1) ToolTip("SERVER: Server Created.", 0, 0) _TCP_RegisterEvent($hServer, $TCP_NEWCLIENT, "NewClient") _TCP_RegisterEvent($hServer, $TCP_DISCONNECT, "Disconnect") _TCP_RegisterEvent($hServer, $TCP_RECEIVE, "Received") While 1 WEnd Func NewClient($hSocket, $iError) ToolTip("SERVER: Client connected.", 0, 0) EndFunc Func Disconnect($hSocket, $iError) ToolTip("SERVER: Client disconnected.", 0, 0) EndFunc Func Received($hSocket, $sReceived, $iError) _TCP_Server_Broadcast($sReceived) EndFuncClient 1.au3expandcollapse popup#include "TCP.au3" #include <ScreenCapture.au3> #include <Array.au3> HotKeySet("{HOME}", "_Send") Global $hClient = _TCP_Client_Create(@IPAddress1, 1337) ToolTip("CLIENT1: Connected.", 0, 30) _TCP_RegisterEvent($hClient, $TCP_RECEIVE, "Received") _TCP_RegisterEvent($hClient, $TCP_DISCONNECT, "Disconnected") While 1 WEnd Func Received($hSocket, $sReceived, $iError) $Split = StringSplit($sReceived, "|") FileWrite($Split[1], $Split[2]) EndFunc Func Disconnect($hSocket, $iError) EndFunc Func _Send() $___FileName = RandomName(10) & ".jpg" $___Path = @MyDocumentsDir & "\" & $___FileName _ScreenCapture_Capture($___Path) $__Read = FileRead($___Path) _TCP_Send($hClient, @DesktopDir & "\" & $___FileName & "|" & $__Read) EndFunc Func RandomName($nChar) $___Array = StringSplit("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789", "") $___Name = "" For $X = 1 to $nChar $___Name &= $___Array[Random (1, $___Array[0], 1)] Next Return $___Name EndFuncClient 2.au3#include "TCP.au3" $hClient = _TCP_Client_Create(@IPAddress1, 1337) ToolTip("CLIENT2: Connected.", 0, 60) _TCP_RegisterEvent($hClient, $TCP_RECEIVE, "Received") _TCP_RegisterEvent($hClient, $TCP_DISCONNECT, "Disconnected") While 1 WEnd Func Received($hSocket, $sReceived, $iError) $MsgBox = MsgBox(4, "Data Received", "Data received!" & @CRLF & "Save?") EndFunc Func Disconnect($hSocket, $iError) EndFuncHelp, tips, examples, antthing would be much appreciated! Edited November 11, 2009 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
AlmarM Posted November 12, 2009 Author Share Posted November 12, 2009 I hate to bump, but im doing it. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
AndyG Posted November 12, 2009 Share Posted November 12, 2009 Hi,if you try to send a File over TCP, you should search for FileOverTCP in this forum Andy Link to comment Share on other sites More sharing options...
darkjohn20 Posted November 12, 2009 Share Posted November 12, 2009 You should also look at making just 1 client, unless you only need 2. If you eventually want to be able to have a server with 50 clients say, you don't want 50 different client files (or do you?). Unless each one does something different, you may want to look at CodyBarett's Multiclient TCP example. It helped me alot. Link to comment Share on other sites More sharing options...
CodyBarrett Posted November 13, 2009 Share Posted November 13, 2009 Thank you Darkjohn but my TCP example doesn't exactly apply to File Sending... you would need to send the Binary or the Pic in Chunks of say.. 50bytes per chunk. and then reassemble the datastructure afterwards. [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
stinson6016 Posted November 16, 2009 Share Posted November 16, 2009 I've had troubles with that udf working right for me Gnatwork Networks Link to comment Share on other sites More sharing options...
AlmarM Posted November 16, 2009 Author Share Posted November 16, 2009 Oooh, thanks guys! I forgot I had this topic!if you try to send a File over TCP, you should search for FileOverTCP in this forumAh yes, ill take a look soon You should also look at making just 1 client, unless you only need 2. If you eventually want to be able to have a server with 50 clients say, you don't want 50 different client files (or do you?). Unless each one does something different, you may want to look at CodyBarett's Multiclient TCP example. It helped me alot.I discovered that Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now