Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

TCP UDF, Event driven!


  • Please log in to reply
317 replies to this topic

#301 zhaozhigang

zhaozhigang

    Seeker

  • Normal Members
  • 1 posts

Posted 19 September 2011 - 01:43 AM

I already have my app running on the old UDF, but since you left all the old functions in it, i will upgrade







#302 Vision

Vision

    Wayfarer

  • Active Members
  • Pip
  • 72 posts

Posted 05 April 2012 - 10:50 AM

Hello,

im useing this tcp udf in one of my main "projects", im currently working towards a new version and i never had problems with this udf, but now the data i want to send has changed in size, so i have changed:

Local $sDataBuff = TCPRecv( $hSocket, 1024)

in TCP.udf -> line ~200 (server) and -> line ~400 (client)

from 1024 to 102400 to recvieve more data (lol how clever)

but the data is not increasing, on the same amount of data in sample 8000 characters are send from the server randomly only 1297 to 2601 characters are recieved on the client.


hope you can help me to solve this
.
and sorry for bumping a old thread

regards

Edited by Vision, 05 April 2012 - 10:55 AM.


#303 Kip

Kip

    Into the JavaScript

  • Active Members
  • PipPipPipPipPipPip
  • 1,690 posts

Posted 06 April 2012 - 02:37 PM

Are you receiving ~1297 bytes only once?
Or multiple packets of that size? If so, you should just concatenate the different pieces of data.

#304 Cokov

Cokov

    Seeker

  • Normal Members
  • 3 posts

Posted 07 May 2012 - 12:39 AM

Hello
I managed to use this with local network but i dont know how to make it work global, so that i can send client to my friends while server works at my home.
Is there any way i can to that?

#305 Kip

Kip

    Into the JavaScript

  • Active Members
  • PipPipPipPipPipPip
  • 1,690 posts

Posted 07 May 2012 - 02:07 PM

Hello
I managed to use this with local network but i dont know how to make it work global, so that i can send client to my friends while server works at my home.
Is there any way i can to that?

Yes, within the router, forward the port you are using to your computer.
Google how to do it for your specific router.

#306 Cokov

Cokov

    Seeker

  • Normal Members
  • 3 posts

Posted 09 May 2012 - 11:30 AM

That worked, thanks. ;)

#307 denchu

denchu

    Seeker

  • Active Members
  • 6 posts

Posted 27 May 2012 - 12:02 PM

Hello, Kip. Nice functions.
I have a little question.$TCP_SEND event occures once and if no data sended and no other activity on socket event never posted again, right? It's mean that i need some flag variable in my script to store sending condition if i does not send data at the moment of $TCP_SEND occurance. Or event will be posted again and again even no activities on socket?

#308 denchu

denchu

    Seeker

  • Active Members
  • 6 posts

Posted 03 June 2012 - 08:06 AM

After some experiments i have found the answer. $TCP_SEND wil be posted right after connect to the peer and after disapearance of some error. In most case i have 10035 error(send buffer of asocket is full) when sending data and then have $TCP_SEND.

I wrote wrapper function and put it in tcp.au3 so i don't need $TCP_SEND in my main scripts anymore. I just fill the buffer and TCP.au3 make all work for me.

AutoIt         
#region Sending data Func _TCP_Send_to_Buffer($hSocket, $Data) If Not BinaryLen($Data) Then Return 1;we did it :) Local $iSocket = __TCP_SocketHandle2SocketID($hSocket) if @error then Return Seterror(1,0,0) If BinaryLen($__TCP_SEND_Buffers[$iSocket]) > $__TCP_BUFFERSIZE * 1024 Then;buffer is full $__TCP_BUFFERSIZE is 10% of free memory.   Return SetError(1, BinaryLen($__TCP_SEND_Buffers[$iSocket]), 0) EndIf Local $DataType = IsBinary($Data) $Data = __TCP_Cry($iSocket, $Data, $DataType) ;i crypt and zlib compress my data ;in this part i make my own packet structure - 5bytes header with datasize and datatype info Local $DataSize = BinaryLen($Data) If $DataType = 1 Then   Local $Header = Binary(Binary(True) & Binary($DataSize)) Else   Local $Header = Binary(Binary(False) & Binary($DataSize)) EndIf $__TCP_SEND_Buffers[$iSocket] &= $Header $__TCP_SEND_Buffers[$iSocket] &= $Data $__TCP_SEND_Buffers[$iSocket] = Binary($__TCP_SEND_Buffers[$iSocket]) If $__TCP_SOCKETS[$iSocket][$iSendFlag] Then ;i need flag to take $TCP_SEND state Local $iSendres = __TCP_SendBuffer($hSocket) Return 1 EndFunc   ;==>_TCP_Send_to_Buffer Func __TCP_SEND($hSocket, $iError) ;$TCP_SEND event calls this func $iSocket = __TCP_SocketHandle2SocketID($hSocket) If Not $iError Then $__TCP_SOCKETS[$iSocket][$iSendFlag] = True __TCP_SendBuffer($hSocket) EndFunc   ;==>__TCP_SEND Func __TCP_SendBuffer($hSocket) Local $iSocket = __TCP_SocketHandle2SocketID($hSocket) If Not $__TCP_SOCKETS[$iSocket][$iSendFlag] Then Return SetError(0, 0, 0) Local $bytesent = 0 While BinaryLen($__TCP_SEND_Buffers[$iSocket])     $bytesent = TCPSend($hSocket, $__TCP_SEND_Buffers[$iSocket])     If @error = 10035 Then;WS buffer is full              $__TCP_SEND_Buffers[$iSocket] = BinaryMid($__TCP_SEND_Buffers[$iSocket], $bytesent + 1)              $__TCP_SOCKETS[$iSocket][$iSendFlag] = 0               Return SetError(1, 10035, 0);error when sending winsock send window is full   ElseIf @error Then ; some other error maybe disconnect               $__TCP_SEND_Buffers[$iSocket] = BinaryMid($__TCP_SEND_Buffers[$iSocket], $bytesent + 1)               $__TCP_SOCKETS[$iSocket][$iSendFlag] = 0               Return SetError(2, @error, 0);error when sending   EndIf   $__TCP_SEND_Buffers[$iSocket] = BinaryMid($__TCP_SEND_Buffers[$iSocket], $bytesent + 1) WEnd Return 1 EndFunc   ;==>__TCP_SendBuffer #endregion Sending data

code is not ideal but it works for me. In main script i send data in chunks.

#309 poperann

poperann

    Seeker

  • Normal Members
  • 1 posts

Posted 21 June 2012 - 05:57 AM

Aloha.

I'm really lost to this TCP with the example.

I have read this post from the beginning, and there were different TCP / Client / server.


I tried to setup in my office but it shows that the "Could not connect...."

When I do download the 3 different .au3 files.... I only edit the TCP.au3 File and change the IP to the server's IP.... right???

Awwww.. please Help.

Thank You Sooo much

#310 Valiant8086

Valiant8086

    Seeker

  • Active Members
  • 10 posts

Posted 17 July 2012 - 07:36 AM

Hi.
I think this is exactly what I have been looking for. I'm stuck just now though, can't seem to get my server to notice a message from the client.

Here's the client code:

#include <GUIConstantsEx.au3>
#include <TCP.AU3>
Func Connected($connection, $iError)
If not $iError Then
TrayTip("Client", "Connected...", 5)
Else
TrayTip("Client", "Failed to connect!", 5, 3)
EndIf
EndFunc
func disconnected($connection, $iError)
TrayTip("Client", "Connection closed or dropped", 5, 2)
endFunc
func receive($session, $iError)
TrayTip("Client", "received", 5); not sure if this works, the server is where the problem is that I know of
endFunc
func disconnect()
_TCP_Client_Stop($connection)
endFunc
func process(); my gui has a button to click that calls this
msgbox (0, "", "processing "&guiCtrlRead($input));This works, but the msgbox on the server doesn't pop up after I ok this
TCPSend($connection, guiCtrlRead($input)); input is an edit field in the client to type something to try sending to the server
endFunc
Func terminate()
_TCP_Client_Stop($connection)
Exit
endFunc
while 1
if not $connected and isIPV4Address($serverIP) then;$connected is a variable that's assigned properly in code that's stripped from this snippet, same as isIPV4Address
$connection = _TCP_Client_Create($ServerIP, 25999)
_TCP_RegisterEvent($connection, $TCP_RECEIVE, "Received")
_TCP_RegisterEvent($connection, $TCP_CONNECT, "Connected")
_TCP_RegisterEvent($connection, $TCP_DISCONNECT, "Disconnected")
endIf
sleep(500)
wend

That's the end of the client code, here's the server.

global $connection = _TCP_Server_Create(25999)
_TCP_RegisterEvent($connection, $TCP_NEWCLIENT, "NewClient")
_TCP_RegisterEvent($connection, $TCP_DISCONNECT, "Disconnect")
_TCP_RegisterEvent($connection, $TCP_RECEIVE, "Receive")
Func NewClient($session, $iError)
_TCP_Send($session, "connected"); Haven't set up the receive function on the client so don't know if it works that way.
EndFunc
Func Disconnect($session, $iError)
;I have a notification coded in here
EndFunc
func getIP($IP)
return _TCP_Server_ClientIP($IP);works great till I try to use it to get the IP of a disconnected client. Any suggestions on that while we're at it?
endFunc

func receive($receivedData, $iError)
msgbox(0, "server", "received "&$receivedData); doesn't seem to be working though the process function in the client does pop up it's own msgbox
endFunc
func terminate()
_TCP_Server_Broadcast("shutdown")
_TCP_Server_Stop()
sleep(1000)
exit
endFunc
while 1
sleep(100)
wend

#311 ghost911

ghost911

    Seeker

  • Normal Members
  • 4 posts

Posted 24 November 2012 - 10:44 AM

help me please i want send file with the udf

#312 Jos

Jos

    Je maintiendrai

  • Developers
  • 23,356 posts

Posted 24 November 2012 - 11:12 AM

help me please i want send file with the udf

couple of questions/remarks:
1. Why do you post in this thread?
2. What have you done/researched yet?
3. You haven't really asked a specific question so what is it yo need help with?

Anyway start your own thread with your support request.

Jos

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#313 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,555 posts

Posted 13 January 2013 - 07:40 PM

A very well designed UDF, but I do have a couple of improvements that could be made perhaps.

1. Run the UDF through Jos' Tidy.
2. Use #forceref to bypass Au3Check (advanced parameters) errors.
3. Remove explicitly declaring loop only variables e.g. Line 230 in _TCP_Server_Stop.
4. You're missing a DllClose for $hWs2_32 and TCPShutdown.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#314 JackER4565

JackER4565

    Seeker

  • Active Members
  • 12 posts

Posted 13 January 2013 - 11:56 PM

Hey, how do I use _TCP_Server_ClientList()?

#315 JonBMN

JonBMN

    Prodigy

  • Banned (NOT IN USE)
  • 160 posts

Posted 10 April 2013 - 08:33 PM

Aloha.

I'm really lost to this TCP with the example.

I have read this post from the beginning, and there were different TCP / Client / server.


I tried to setup in my office but it shows that the "Could not connect...."

When I do download the 3 different .au3 files.... I only edit the TCP.au3 File and change the IP to the server's IP.... right???

Awwww.. please Help.

Thank You Sooo much


No one can help you unless you post your code, because you've obviously got something a little whack. Let us help!


@Valiant8086 - You did not set an IP address in your client script to send to the server, unless you haven't posted all your code..


Hey, how do I use _TCP_Server_ClientList()?


gonna need a little more than that..

Edited by JonBMN, 10 April 2013 - 08:33 PM.


#316 CountyIT

CountyIT

    Wayfarer

  • Banned (NOT IN USE)
  • 98 posts

Posted 29 April 2013 - 10:33 PM

We found the problem. It kind of relates back to guinness's suggestion a couple posts up. It relates to using the Obfuscator. The script runs fine until you compile it with #AutoIt3Wrapper_Run_Obfuscator=y at which point compiling generates a lot of warnings and errors and the resultant exe does not work properly.

By changing the directive to #AutoIt3Wrapper_Run_Obfuscator=n everything works as an exe but it just isn't clean......

#317 Kip

Kip

    Into the JavaScript

  • Active Members
  • PipPipPipPipPipPip
  • 1,690 posts

Posted 30 April 2013 - 11:04 PM

Don't use this UDF.

It is flawed. At the time of writing this I did not fully understand the underlying techniques.
As a result it will seem to fail randomly.
 


Edited by Kip, 30 July 2013 - 07:51 AM.


#318 nullschritt

nullschritt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 411 posts

Posted 29 July 2013 - 10:48 PM

Hello,

im useing this tcp udf in one of my main "projects", im currently working towards a new version and i never had problems with this udf, but now the data i want to send has changed in size, so i have changed:
 

Local $sDataBuff = TCPRecv( $hSocket, 1024)
in TCP.udf -> line ~200 (server) and -> line ~400 (client)

from 1024 to 102400 to recvieve more data (lol how clever)

but the data is not increasing, on the same amount of data in sample 8000 characters are send from the server randomly only 1297 to 2601 characters are recieved on the client.


hope you can help me to solve this
.
and sorry for bumping a old thread

regards

 

I am having this same problem with the Event Driven P2P script based off this script, it's not sendign the data as packets, it's simply cutting off the string when it's send over a network connection, locally there is no limit for TCPSend, but it seems that over a network connection, only so many bytes can be transferred at once.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users