Jump to content

Simple one to one chat over internet


4Ever
 Share

Recommended Posts

Hi,

I want a simple script to enable transmission and reception of text between 2 computers on the Internet without using GUI,

specifying in scripts these variable data:

$serverip

$port

$texttosend

$receivedtext

To test it, a msgbox will display received data when is received, and to input text to send, use InputBox in loop.

I'm beginner in autoit.

I need only one connection, no need fore more.

Please help me.

Link to comment
Share on other sites

You want to first do some basic autoit3 scrips.

Then you want to look at TCPStartup, UDPStartup and all of its related functions.

You may also want to look at 403 forbibben video tut on the subject

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I can't offer something very simple, but you may learn out my old creation:

Completely working(excluding some extra things) lan/internet chat, with sounds and traytips,

client and server(2 in 1) - who started first, - is server. If you are connected and server disconnects,

then client becomes server and listen for incoming connection:)

To connect, you must specify IP address of remote computer inside INI-file,

or (if you have a site) to upload your IP:

#include <Inet.au3>
_INetGetSource("http://www.yoursite.com/ip.php?ip=" & @IPAddress1)

$ip = _INetGetSource("http://www.yoursite.com/file.txt")
if Ping($ip) <> 0 Then MsgBox(0, "Uploaded IP", $ip)

contents of ip.php:

<?
$file = "file.txt";
unlink($file);
$Handle = fopen($file, 'w+');
$ip = $_GET['ip'];
fwrite($Handle, $ip);
fclose($Handle);
?>

and then use _InetGetSource instead of read/write IP from/to ini file..

chatter.zip

Edited by Godless

_____________________________________________________________________________

Link to comment
Share on other sites

Thank you, Godless, but i want some basic stuff.

I tried the following codes, but without success:

CLIENT:

TCPStartup()

$ip = "86.34.52.138"

$connect = TCPConnect ( $ip, 216 )

if $connect = -1 Then
    TCPShutdown ( )
endif
    $datatosend = "Hello!"
TCPSend( $connect, $datatosend)

endif

SERVER:

$ip = "86.34.52.138"

TCPStartUp()

$MainSocket = TCPListen($ip, 216)

$ConnectedSocket = -1
Do
  $ConnectedSocket = TCPAccept($MainSocket)
            
Until $ConnectedSocket <> -1
    $recv =""
    While $recv <> "exit"
   $recv = TCPRecv($ConnectedSocket, 2048)
    
    If $recv <> "" Then 
     MsgBox(4096, "Test", "$recv", 10)
     endif
    
Wend

Note that the other computer have another static ip in scripts.

How to do it? SIMPLE! After that, i will do experiments.. to learn more.

Edited by 4Ever
Link to comment
Share on other sites

SERVER:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

;==============================================
;==============================================
;SERVER!! Start Me First !!!!!!!!!!!!!!!
;==============================================
;==============================================

Example()

Func Example()
    ; Set Some reusable info
    ; Set your Public IP address (@IPAddress1) here.
;   Local $szServerPC = @ComputerName
;   Local $szIPADDRESS = TCPNameToIP($szServerPC)
    Local $szIPADDRESS = @IPAddress1
    Local $nPORT = 33891
    Local $MainSocket, $GOOEY, $edit, $ConnectedSocket, $szIP_Accepted
    Local $msg, $recv

    ; Start The TCP Services
    ;==============================================
    TCPStartup()

    ; Create a Listening "SOCKET".
    ;   Using your IP Address and Port 33891.
    ;==============================================
    $MainSocket = TCPListen($szIPADDRESS, $nPORT)

    ; If the Socket creation fails, exit.
    If $MainSocket = -1 Then Exit


    ; Create a GUI for messages
    ;==============================================
    $GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")", 300, 200)
    $edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
    GUISetState()


    ; Initialize a variable to represent a connection
    ;==============================================
    $ConnectedSocket = -1


    ;Wait for and Accept a connection
    ;==============================================
    Do
        $ConnectedSocket = TCPAccept($MainSocket)
    Until $ConnectedSocket <> -1


    ; Get IP of client connecting
    $szIP_Accepted = SocketToIP($ConnectedSocket)

    ; GUI Message Loop
    ;==============================================
    While 1
        $msg = GUIGetMsg()

        ; GUI Closed
        ;--------------------
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop

        ; Try to receive (up to) 2048 bytes
        ;----------------------------------------------------------------
        $recv = TCPRecv($ConnectedSocket, 2048)

        ; If the receive failed with @error then the socket has disconnected
        ;----------------------------------------------------------------
        If @error Then ExitLoop

        ; Update the edit control with what we have received
        ;----------------------------------------------------------------
        If $recv <> "" Then GUICtrlSetData($edit, _
                $szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($edit))
    WEnd


    If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)

    TCPShutdown()
EndFunc   ;==>Example

; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
    Local $sockaddr, $aRet

    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc   ;==>SocketToIP

CLIENT:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

;==============================================
;==============================================
;CLIENT! Start Me after starting the SERVER!!!!!!!!!!!!!!!
;==============================================
;==============================================

Example()

Func Example()
    ; Set Some reusable info
    ;--------------------------
    Local $ConnectedSocket, $szData
    ; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address
;   Local $szServerPC = @ComputerName
;   Local $szIPADDRESS = TCPNameToIP($szServerPC)
    Local $szIPADDRESS = @IPAddress1
    Local $nPORT = 33891

    ; Start The TCP Services
    ;==============================================
    TCPStartup()

    ; Initialize a variable to represent a connection
    ;==============================================
    $ConnectedSocket = -1

    ;Attempt to connect to SERVER at its IP and PORT 33891
    ;=======================================================
    $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT)

    ; If there is an error... show it
    If @error Then
        MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
        ; If there is no error loop an inputbox for data
        ;   to send to the SERVER.
    Else
        ;Loop forever asking for data to send to the SERVER
        While 1
            ; InputBox for data to transmit
            $szData = InputBox("Data for Server", @LF & @LF & "Enter data to transmit to the SERVER:")

            ; If they cancel the InputBox or leave it blank we exit our forever loop
            If @error Or $szData = "" Then ExitLoop

            ; We should have data in $szData... lets attempt to send it through our connected socket.
            TCPSend($ConnectedSocket, $szData)

            ; If the send failed with @error then the socket has disconnected
            ;----------------------------------------------------------------
            If @error Then ExitLoop
        WEnd
    EndIf
EndFunc   ;==>Example
Edited by Godless

_____________________________________________________________________________

Link to comment
Share on other sites

Or you might want to try the search engine to find the previous times when it was done.

http://www.autoitscript.com/forum/index.php?app=core&module=search&section=search&do=quick_search&search_app=core&fromsearch=1

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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