Sign in to follow this  
Followers 0
sfunk1x

TCP communications

13 posts in this topic

Hey all -

Here's the lowdown. I have a machine that is going to handle multiple sets of ISOs for a program suite I am testing. The machines that will be testing will require the machine handling the ISOs to unmount one ISO and then mount the next ISO in sequence (ie change from ISO disk 1 to ISO disk 2, etc). How I am trying to write this is when the test machine reaches the window that informs the end user to insert another disk, I would like the test machine to communicate over the network and notify the ISO machine to change ISOs.

As you can see below, I would like to perform this with the network, and am trying TCP. I have not written an Autoit script with TCP functionality before, so I'm wondering if I can just get a boot in the right direction from someone here as to how I should handle this - not necessarily have someone write it for me although any examples would be greatly appreciated.

------------------------

Here's the code I currently have. it's not much, but I'm a little confused as to where I should take it next. I'm working on this constantly so it's ever growing (and getting deleted when it doesn't work ;) ). Thanks in advance for any help supplied.

$dt_server_ip = "70.98.109.138"

$lite_socket = TCPListen($dt_server_ip, 54001, 100)

$std_socket = TCPListen($dt_server_ip, 54002, 100)

$dlx_socket = TCPListen($dt_server_ip, 54003, 100)

$dvd_socket = TCPListen($dt_server_ip, 54004, 100)

$ppd_socket = TCPListen($dt_server_ip, 54005, 100)

TCPStartup()

Do

TCPConnect($dt_server_ip, $lite_socket)

TCPConnect($dt_server_ip, $std_socket)

TCPConnect($dt_server_ip, $dlx_socket)

TCPConnect($dt_server_ip, $dvd_socket)

TCPConnect($dt_server_ip, $ppd_socket)

If

#cs

This is where I'm kinda lost as what I've tried hasn't worked.

#ce

Then

Until @error

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you have a SMTP server on the LAN - it might be easier to send an e-mail. See this post:

http://www.autoitscript.com/forum/index.ph...969entry97969

Edit: I see that I did not comprehend the request - but I'll leave the post for what it is worth....

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Hey all -

Here's the lowdown. I have a machine that is going to handle multiple sets of ISOs for a program suite I am testing. The machines that will be testing will require the machine handling the ISOs to unmount one ISO and then mount the next ISO in sequence (ie change from ISO disk 1 to ISO disk 2, etc). How I am trying to write this is when the test machine reaches the window that informs the end user to insert another disk, I would like the test machine to communicate over the network and notify the ISO machine to change ISOs.

As you can see below, I would like to perform this with the network, and am trying TCP. I have not written an Autoit script with TCP functionality before, so I'm wondering if I can just get a boot in the right direction from someone here as to how I should handle this - not necessarily have someone write it for me although any examples would be greatly appreciated.

------------------------

Here's the code I currently have. it's not much, but I'm a little confused as to where I should take it next. I'm working on this constantly so it's ever growing (and getting deleted when it doesn't work ;) ). Thanks in advance for any help supplied.

$dt_server_ip = "70.98.109.138"

$lite_socket = TCPListen($dt_server_ip, 54001, 100)

$std_socket = TCPListen($dt_server_ip, 54002, 100)

$dlx_socket = TCPListen($dt_server_ip, 54003, 100)

$dvd_socket = TCPListen($dt_server_ip, 54004, 100)

$ppd_socket = TCPListen($dt_server_ip, 54005, 100)

TCPStartup()

Do

TCPConnect($dt_server_ip, $lite_socket)

TCPConnect($dt_server_ip, $std_socket)

TCPConnect($dt_server_ip, $dlx_socket)

TCPConnect($dt_server_ip, $dvd_socket)

TCPConnect($dt_server_ip, $ppd_socket)

If

#cs

This is where I'm kinda lost as what I've tried hasn't worked.

#ce

Then

Until @error

it seems like you may be going about this kind of the hard way... another thing you could try, is to have your script that is running on each of the clients create/update a file on the iso server, saying what iso that machine needs. then the server script could just check the files in that directory, if a different iso is specified than is currently mounted, then switch....it's a little slower, and may not be as pretty, but it will work, and will probably work out to be alot less code, and alot more readable.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

I can give the file modification a try - I'm going to try an .ini file. I'll make a shared folder on the server and map that on the clients, and have the clients modify the .ini file in correlation with what SKU they are running. I will then have the server constantly read the .ini to ensure it's on the same disk.

Any hints on constructing the loop so it is constantly scanning the .ini file, then makes changes when necessary? How could I implement this so the installing machine doesn't freak out if/when the server doesn't change the ISOs in a timely manner?

Share this post


Link to post
Share on other sites

I can give the file modification a try - I'm going to try an .ini file. I'll make a shared folder on the server and map that on the clients, and have the clients modify the .ini file in correlation with what SKU they are running. I will then have the server constantly read the .ini to ensure it's on the same disk.

Any hints on constructing the loop so it is constantly scanning the .ini file, then makes changes when necessary? How could I implement this so the installing machine doesn't freak out if/when the server doesn't change the ISOs in a timely manner?

few things, can't have it CONSTANTLY checking file, because the file needs to close in order for the clients to update it when they need a disk. that's why i was suggesting plain text instead of ini. then your loops would all be using FileOpen() and FileClose() to access the files, and you could just evaluate @error to handle errors if client and server are trying to open the file at the same time. Personally i don't have much experience with ini's because i just don't use them, i use text files, log files, or registry entries to accomplish the same things. (not all at once of course that would just be silly).

as far as handling slow mounting, your client script should know the label of the drive to be mounted and the letter it will be mounted to, so you could just use DriveGetLabel() and DriveStatus() to make sure the drive is ready... just throw in a loop like:

FileWriteLine($nextdrive,$isotoload)
while 1
if DriveGetLabel("G:\") = $isotoload then ExitLoop
sleep(100)
WEnd

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Just to drop this out there since I still want to figure out proper TCP/UDP syntax in Autoit...

This is the server....

---------------------------

Opt("Trayicondebug",1)

; Script Start - Add your code below here

$dt_server_ip = "***.***.109.138"

$dtools_exec = "C:\dtools\daemon.exe"

$lite_socket = TCPListen($dt_server_ip, 54001, 100)

$std_socket = TCPListen($dt_server_ip, 54002, 100)

$dlx_socket = TCPListen($dt_server_ip, 54003, 100)

$dvd_socket = TCPListen($dt_server_ip, 54004, 100)

$ppd_socket = TCPListen($dt_server_ip, 54005, 100)

$lite_recv = TCPRecv($lite_socket, 512)

TCPStartup()

While 1

If $lite_recv = "unmount" Then

Run($dtools_exec & '-unmount 0')

EndIf

WEnd

---------------------------

this is the client

-------------------

$ISO_Server = "***.***.109.138"

$ISO_Socket = "54001"

TCPStartup()

TCPConnect($ISO_Server, $ISO_Socket)

TCPSend($ISO_Socket, "unmount")

--------------------

Keep in mind I wasn't going for code complete, was just looking for confirmation that I understand proper syntax. Unfortunately, it doesn't work. Can someone show me what I'm missing here?

Edited by sfunk1x

Share this post


Link to post
Share on other sites

OK, I should have explained the code I pasted up there..

The server is controlling daemon tools. It is waiting for the client to send it the "unmount" message, and then it will execute the unmount command. I double checked at a cli to ensure the command syntax was proper.

I copied & pasted your scripts into files to test them, and it seems to loop between lines 16 & 19. with the syntax shown, will it ever exit that particular loop and execute the code below?

Thanks for the help!

Another thing.. it seems like Scite and the Autoit beta compiler don't appear to understand the TCP functions... is there an include that I am missing?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Replaced *'s with proper ip, and while everything does Syntax check ok, I'm still not getting proper communication between the two machines. I am going to throw ethereal on another machine here to watch the client box and see if it's actually sending anything out.

I'm determined to figure out the proper syntax so I can get it working this way. Unless it can't be done, of course...

Thanks!

Edited by sfunk1x

Share this post


Link to post
Share on other sites

OK, so I solved this problem by not using TCP, directly anyway.

I have the server running in a continuous loop (all commands within a Do... Until loop). It appears as if the server does everything I want it to, albeit very un-elegantly. it also appears there is 100% CPU utilization because it is constantly checking to see if particular files exist on the hard drive. I currently have my client machines creating text files in a specific network share on the server to communicate what ISO the clients need.

I will post the code first thing tomorrow morning, but I'm wondering if anyone has any ideas of how to perhaps reduce the amount of load that is being placed on the system, through code refinement or perhaps some other form of continual checking as opposed to a Do...Until loop.

Thanks.

Share this post


Link to post
Share on other sites

OK, so I solved this problem by not using TCP, directly anyway.

I have the server running in a continuous loop (all commands within a Do... Until loop). It appears as if the server does everything I want it to, albeit very un-elegantly. it also appears there is 100% CPU utilization because it is constantly checking to see if particular files exist on the hard drive. I currently have my client machines creating text files in a specific network share on the server to communicate what ISO the clients need.

I will post the code first thing tomorrow morning, but I'm wondering if anyone has any ideas of how to perhaps reduce the amount of load that is being placed on the system, through code refinement or perhaps some other form of continual checking as opposed to a Do...Until loop.

Thanks.

Do you need to know to the nanosecond when the ISO change is required? Maybe you could put a pause in the loop to lighten the burden on the remote CPU, say for 30 seconds or one minute, or even five minutes...

Examine the sleep command in the help file. ;)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Yes, the server has to know when it's required. The iso change is required during the installation of the app on the client. The client is also being automated with a script.

This is why I wanted to use the TCP communications to handle this.. ;-) But unfortunately, I can't even get the examples in the Beta working together.

Edited by sfunk1x

Share this post


Link to post
Share on other sites

Seriously, the help here is astounding. I'm at home at the oment, but I'm going to give this a shot on a couple of boxes when I get to work.

Thanks!

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

OK, I circumvented the need for a TCP solution, but I'm; still trying to get it to work via TCP in my spare time. Again, server is waiting for strings from the clients to tell it which iso to mount where. here is the code the server runs:

Server code:

---------------------

$ip = @IPAddress1

$port = 54001

$mainsocket = TCPListen($ip, $port)

$dtools = ("c:\program files\d-tools\daemon.exe")

$lite = ("c:\test\t1\install.iso")

$essentials = ("c:\test\t2\install.iso")

$std_inst = ("c:\test\t3\install.iso")

$std_prog = ("c:\test\t3\program.iso")

ToolTip("Listening for clients on " & $ip & " and port " & $port)

;HotKeySet("`", "StopScript")

While 1

Do

$connectedsocket = TCPAccept($mainsocket)

Until $connectedsocket > 0

$err = 0

Do

$msg = TCPRecv($connectedsocket, 512)

$err = @error

If String($msg) = "lite" Then

Run($dtools & " -mount 0," & $lite)

EndIf

If String($msg) = "essentials" Then

Run($dtools & " -mount 0," & $essentials)

EndIf

If String($msg) = "std_inst" Then

Run($dtools & " -mount 0," & $std_inst)

EndIf

If String($msg) = "std_prog" Then

Run($dtools & " -mount 0," & $std_prog)

EndIf

Until $err

TCPCloseSocket($connectedsocket)

WEnd

------------------------

Server runs, but I'm not sure if it's doing it's job. The client runs the following code:

Client Code:

------------------------

$iso_ip = "70.98.109.240"

$iso_port = "54001"

$mainsocket = TCPConnect($iso_ip, $iso_port)

$msg_inst = "std_inst"

$msg_prog = "std_prog"

; this is a snippet of code from the whole script, dealing specifically with changing isos

WinWait("Installer Information", "")

If WinExists("Installer Information", "") Then

TCPStartup()

TCPSend($mainsocket, $msg_prog)

TCPCloseSocket($mainsocket)

EndIf

-----------------------

So in theory, the client comes across the "Installer Information" window, then opens up a TCP send function and send the "std_prog" string via the variables on the TCPSend line, correct? Then the socket is closed. Unfortunately, when I run the variable declarations and the 3 specific TCP cod elines, nothing happens. The server does not respond, nor does my sniffer detect any traffic leaving the client in question.

Can anyone point out any obvious errors in the code above?

Edited by sfunk1x

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0