Jump to content

Simple tcp communication


piccaso
 Share

Recommended Posts

Get http://www.autoitscript.com/fileman/users/public/piccaso/tcp_poc.zip and Extract to a new folder.

Run Server.exe (or server.au3) to start.

Run nc_client.bat to start a client (this is just uses windows port of netcat because i dont like the M$ telnet client)

type 'help' (without the quotes and in lower case) to see the Available commands

btw: piccaso.au3 is just my Common Functions include file, not all functions are needet but some depend on each other so i includet the whole file. And of course you dont have to follow the instructions written in there as comment

This script uses netcat to comunicate over the network.

Reciving works fine but sending doesent work with every char jet (try 'send' with the client)

if the script crashes for some reason you have to terminate nc.exe manualy or it will listen there until you reboot and you cant use port 1234

CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Link to comment
Share on other sites

Could this be updated to send and recieve binary so that files could be transferred?

<{POST_SNAPBACK}>

Basically it's already possible. You just have to start nc.exe by yourself.

nc 192.168.4.5 1234 <data.bin

This sends the file data.bin to the process listening on the destination.

If you run nc like this, you can receive such a data stream and write it to a file (has to be started before the sender is starting to send):

nc -l -p 1234 > data.bin

You also have to know how big the file is going to be since nc.exe doesn't exits after sending the whole file. So basically you have to loop until the file is big enough and then terminate nc.exe

Disclaimer: I didn't check the options but used what I have in my memory. So if it doesn't work, you have to check the options of nc.exe and fix what I've pasted.

What you cannot do is to keep a connection alive and interact through it (it's also possible but it would need tail.exe and a lot of workarounds).

EDIT: two errors fixed

Edited by sugi
Link to comment
Share on other sites

Could this be updated to send and recieve binary so that files could be transferred?

<{POST_SNAPBACK}>

Like sugi said, you can use parts of my example to send the filesize to the other side...

or fire up a little webserver (you can use apache without installer checkout 'uniform server' at sourceforge for an example) and use InetGet() ...

Disclaimer: I didn't check the options but used what I have in my memory. So if it doesn't work, you have to check the options of nc.exe and fix what I've pasted.

<{POST_SNAPBACK}>

looks correct :)
CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Link to comment
Share on other sites

@this-is-me

:) you inspired me :)

you could encode your bin using uuencode or base64 (i had some comandline tools in my toolbox - http://www.autoitscript.com/fileman/users/public/piccaso/bin_encoder.zip)

and send/recive it using this fuctions:

func _Tunnle($in)
   Local $i,$out
   for $i = 1 to Stringlen($in)
      $out = $out & hex(asc(stringmid($in,$i,1)),2) & " "
   Next
   Return $out
EndFunc
func _UnTunnle($in)
   Local $i,$out,$t
   $t = StringSplit($in," ")
   for $i = 1 to UBound($t)-1
      $out = $out & chr(dec($t[$i]))
   Next
   Return $out
EndFunc

currently _nc_send() cant send funny chars so "Tunnle" uses only hex numbers and spaces

CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...