Jump to content

Sending 'MsgBox's via TCP/IP


Recommended Posts

Often times at school, I'll need to send a message to myself and I don't have a pen to write on my hand, and I dont' check email often enough, so I was thinking about writing a program that I could run from school (maybe even web-based?) and it would send an Autoit MsgBox to my computer... I know NOTHING about the TCPIP commands in Autoit, but I think I know this much:

A program would need to be running on BOTH computers... right?

If I want to password protect the computers, I will need a website that has all IPs/Username with IPs and their passwords, right?

What else do I need to do this? Or if anyone has any very SIMPLE code to help me out, I'd greatly appreciate that, too. Thanks!

Link to comment
Share on other sites

Run this at your comp at home:

;Server Script. RUN FIRST
TCPStartUp()
$MainSocket = TCPListen(TCPNameToIP(@computername), 65432,  100 )
If $MainSocket = -1 Then Exit
While 1
    $ConnectedSocket = TCPAccept( $MainSocket)
    If $ConnectedSocket >= 0 Then
        ExitLoop
    EndIf
Wend
While 1
    $Message=TCPRecv($ConnectedSocket,2048)
    Sleep(25)
    If $Message<>"" Then
        MsgBox(0,"",$Message)
    EndIf
WEndoÝ÷ Ù8^»§¶¬jܨº»%jëh×6;Client Script. RUN SERVER FIRST
TCPStartUp()
$ServerIp="xx.xx.xx.xx";Enter your remote comp's IP here
$MainSocket=TCPConnect($ServerIp, 65432)
If $MainSocket = -1 Then Exit
msgbox(0,"","connected",1)
$Message=InputBox("","Enter the message you wish to send to your computer")
if @error Then Exit
TCPSend($MainSocket,$Message)

You should look for an alternative way of showing the messages, because MsgBox will pause the server and you will only be able to send one message.

You can try it at your own computer. Run the server, then run the client and enter your own IP. Try sending the message and the msgbox should pop up.

You might have lots of trouble with firewalls too...

Link to comment
Share on other sites

So, punching a hole through 2 different firewalls seems feasible but e-mailing yourself doesn't?

It's not punching a hole in any firewall... you need to be running the program on that computer in order for it to work, and it's no more complicated than a messinging program or an online game.

Oh, and Nahuel, thanks very much, I will try this when I get home!

Link to comment
Share on other sites

It's not punching a hole in any firewall... you need to be running the program on that computer in order for it to work, and it's no more complicated than a messinging program or an online game.

Well... you will need to punch a hole in your firewall and at school... When you run the server script at home, you'll get a warning asking if you want to unblock it...

Link to comment
Share on other sites

Hmmm, it doesn't work.... I ran the server, clicked 'Unblock' then 'Allow' then ran the other script after entering my IP from www.whatsmyip.org or whatever (69.133.11.238).... but the second script just closes immediately

Are you trying this on two PC's inside of your school? I'm sure they won't be happy if you are...
Link to comment
Share on other sites

Hmmm, it doesn't work.... I ran the server, clicked 'Unblock' then 'Allow' then ran the other script after entering my IP from www.whatsmyip.org or whatever (69.133.11.238).... but the second script just closes immediately

You mean the client? If it closes immediately is beacause it can't connect. Are you trying this using your own computer as server and client?

Run the server in your comp, and then run this also in your comp:

;Client Script. RUN SERVER FIRST
TCPStartUp()
$MainSocket=TCPConnect(TCPNameToIP(@ComputerName), 65432)
If $MainSocket = -1 Then Exit
msgbox(0,"","connected",1)
$Message=InputBox("","Enter the message you wish to send to your computer")
if @error Then Exit
TCPSend($MainSocket,$Message)
Link to comment
Share on other sites

It's not punching a hole in any firewall... you need to be running the program on that computer in order for it to work, and it's no more complicated than a messinging program or an online game.

Oh, and Nahuel, thanks very much, I will try this when I get home!

It is more complicated than any other messaging program because they all use a "middleman" server where messages are passed through. This bypasses the firewall because there is a constant connection between the clients and said server.

You might be able to forward the necessary ports on your home router but if you are in a dorm you won't have much luck. Also you are assuming the outbound connection isn't being blocked.

Link to comment
Share on other sites

Hmm... that second script said connected and popped up the input box, but that did nothing.

Both of these computers are at home, but when I checked whatsmyip.org, they moth have the same IP address..... that's kinda weird... or maybe it isn't....

No no, you are doing it wrong.. Whatismyip.org will tell you your public IP address. The one your ISP gives you. It's the same number for all the computers that are behind your router. Inside your LAN network, you use private IP's. To know the private IP of your PC, use the macro: @IPAddress1 or run cmd.exe and type ipconfig.

Find out what your server computer's IP is (using one of the methos I mentioned above). Run the server script there (you don't need to do any modifications there).

Now go to another computer, edit the client script and add the server's IP. Then run it.

If it works good, you'll get the 'connected' popup and the inputbox. Type whatever you want to say in the inputbox and it should popup in your server computer.

Hope it's clearer now :)

Link to comment
Share on other sites

try an alternate solution..

run an FTP server at home.. (Make you sure DO NOT use adminstrator/password as the login !!)

The data gets written to INETPUB\ftproot.. or whatever directory you decide on your machine at home..

then use autoit.to read the files.. pop them up and delete them..

all uou need at school or remote anywhere is an FTP client and notepad

Link to comment
Share on other sites

This is my first go at coding in autoit, please tell me if anything is wrong.

Server:

;Server Script. RUN FIRST
#include <GuiConstants.au3>
$MessageOld = ""
$i = 0
GUICreate("Server Client", 195, 170)
Local $History = GUICtrlCreateEdit("", 10, 10, 175, 150, $ES_READONLY)
GUISetState()

TCPStartUp()
$MainSocket = TCPListen(TCPNameToIP(@computername), 65432,  100 )

If $MainSocket = -1 Then Exit
    While 1
    $ConnectedSocket = TCPAccept( $MainSocket)
    If $ConnectedSocket >= 0 Then
        ExitLoop
    EndIf
Wend

While 1
    $Message=TCPRecv($ConnectedSocket,2048)
    Sleep(25)
    If $Message<>"" Then
        $MessageShow = $MessageOld & $Message
        GuiCtrlSetData($History, $MessageShow)
        $MessageOld = $MessageShow & ", "
    EndIf
WEnd

Few bugs

* When you close the client you have to restart the server

Edited by benscroggs
Link to comment
Share on other sites

This is my first go at coding in autoit, please tell me if anything is wrong.

It works :)

However, I hope you understand this:

TCPConnect(TCPNameToIP(@ComputerName), 65432)

I made this to test only. This will only work if the same computer is server and client. If you want to do it with two computers, then you must replace TCPNameToIP(@ComputerName) with the IP address of the computer the server is running in.

Link to comment
Share on other sites

It works :)

However, I hope you understand this:

TCPConnect(TCPNameToIP(@ComputerName), 65432)

I made this to test only. This will only work if the same computer is server and client. If you want to do it with two computers, then you must replace TCPNameToIP(@ComputerName) with the IP address of the computer the server is running in.

Yep.

$Ip=InputBox("","Enter the ip of the computer you want to send to",TCPNameToIP(@ComputerName))
$MainSocket=TCPConnect($Ip, 65432)
Edited by benscroggs
Link to comment
Share on other sites

  • 1 month later...

*sigh* I'm sorry, but I just CAN'T get it working. I got it to work using two computers at my house, on the same router, other than that it won't connect.

So my friend runs it, @IPAddress1 tells him his IP is 192.168.100.100. I enter that into the client script and run it, can't connect. He's not running any firewalls that would block it... any ideas?

Link to comment
Share on other sites

It should work if you use the client to connect to that ip. If it doesn't work, change this line of the server TCPConnect(TCPNameToIP(@ComputerName), 65432) by TCPConnect("69.133.11.238", 65432) and then try to connect with the same ip with the client.

I have also had lots of trouble connecting to other computers outside my LAN. Some of them worked fine, some of them didn't.

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...