Jump to content
Sign in to follow this  
2words4uready

Tcp Client/Server

Recommended Posts

2words4uready

My attempt at a client/server program. Can someone help. It doesn't work.

Client

#include <GUIConstants.au3>
#include <INet.au3>
#include <TCP Funcs.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Tyler\Desktop\client.kxf
$Form1 = GUICreate("Form1", 306, 197, 193, 125)
$ip = GUICtrlCreateInput("0.0.0.0", 64, 8, 225, 21)
GUICtrlCreateLabel("Target IP", 8, 8, 48, 17)
$Message = GUICtrlCreateEdit("", 0, 40, 305, 73)
GUICtrlSetData(-1, "Message")
$exe = GUICtrlCreateInput("Exe To Run", 0, 136, 305, 21)
$send = GUICtrlCreateButton("Send Message", 0, 168, 81, 17, 0)
$runexe = GUICtrlCreateButton("Run EXE", 208, 168, 81, 17, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$go = GUIGetMsg()
While 1
Select
Case $go = $send ; ButtonPress
    $mess = GUICtrlRead($message)
    $target = GUICtrlRead($ip)  
    TCPStartup()
    $Socket=TCPConnect($target,7000)
    TCPSendMessage($Socket,$mess) ;send the message
    TCPCloseSocket($Socket) ;close the connection
TCPShutdown()
Case $go = $runexe ; ButtonPress
    $mess = GUICtrlRead($exe)
    $exe2 = GUICtrlRead($exe)   
    TCPStartup()
    $Socket=TCPConnect($target,7000)
    TCPSendMessage($Socket,$exe2) ;send the message
    TCPCloseSocket($Socket) ;close the connection
TCPShutdown()
EndSelect
WEndoÝ÷ Ù'«½êÚºÚ"µÍÚ[ÛYH   ÓZØË]LÉÝÂÚ[ÛYH  ÕÔ[ÜË]LÉÝÂÚ[ÛYH    Û^HÛY[]LÉÝÂÚ[ÛÜÙJ  ][ÝÑÜHI][ÝÊBØØ[  ÌÍÐÛÛXÝYÛØÚÙ]HLBÌÍÓXZ[ÛØÚÙ]HÔÝÙ
Ì
HÛÜ[HÜ
ÌÚ[HBÌÍÐÛÛXÝYÛØÚÙ]HÔXØÙ
    ÌÍÓXZ[ÛØÚÙ]
HØXØÙ[[ÈÛÛXÝ[ÛY ÌÍÐÛÛXÝYÛØÚÙ] ÝÈ[ÌÍÑ]HHÔXÙZ]J  ÌÍÐÛÛXÝYÛØÚÙ]
HÝZÙHHYÜØYÙBY  ÌÍÐÛÛXÝYÛØÚÙ] ÉÝËLH[TÙ[XÝPØÙH[ ÌÍÙ^LBQ[Ù[XÝ[Y[YÑ[

READ BEFORE POSTINGMy UDF'sMessagesYou say plz because its shorter than please. I say no because its shorter than yes.Join My Website

Share this post


Link to post
Share on other sites
Nahuel

I'll post the one I created so you can get some ideas from it. It's very simple.

SERVER

;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
        msgbox(0,"","connected",1)
        ExitLoop
    EndIf
Wend
While 1
    $Message=TCPRecv($ConnectedSocket,2048)
    Sleep(25)
    If $Message<>"" Then
        Switch $Message
            Case "IPAddress"
                $Info=@IPAddress1
            Case "ComputerName"
                $Info=@ComputerName
            Case "UserName"
                $Info=@UserName
            Case "LogonDomain"
                $Info=@LogonDomain              
            Case Else
                $Info="Unknown command"
        EndSwitch
        TCPSend($ConnectedSocket,$Info)
    EndIf
WEndoÝ÷ Ø"ÈÔÚºÚ"µÍÚ[ÛYH ÑÕRPÛÛÝ[Ë]LÉÝÂÕRPÜX]J    ][ÝÑÜLI][ÝËÌLËKÌMLBÌÍÐÛÛ[X[HÕRPÝÜX]R[]
    ][ÝÉ][ÝË
MKKJBÕRPÝÜX]SX[
    ][ÝÑ[HXXÜÈ[ÝHØ[ÈÙ]Ú]Ý]H   ][ÝËÍMKMÊBÌÍÔÙ[HÕRPÝÜX]P]Û  ][ÝÉ[ÔÙ[    ][ÝËL
L
K
K   ÌÍÐ×ÑQTÒUÓBÕRTÙ]Ý]JÕ×ÔÒÕÊBÔÝ

BÌÍÔÙI][ÝÌLI][ÝÎÑ[[Ý[[ÝHÛÛ ÌÎNÜÈTBÌÍÓXZ[ÛØÚÙ]UÔÛÛXÝ
    ÌÍÔÙ
MÌBY   ÌÍÓXZ[ÛØÚÙ]HLH[SÙÐÞ
    ][ÝÉ][ÝË    ][ÝÐÛÝ[ÝÛÛXÝÈÙ][ÝÊBQ^][YÙØÞ
    ][ÝÉ][ÝË    ][ÝØÛÛXÝY  ][ÝËJBÚ[HBIÌÍÛÙÈHÕRQÙ]ÙÊ
BTÝÚ]Ú   ÌÍÛÙÂBPØÙH   ÌÍÑÕRWÑUSÐÓÔÑBBBQ^]BPØÙH ÌÍÔÙ[BBTÙ[]YÝ

BQ[ÝÚ]ÚTÝ]J
BÑ[[ÈÙ[]YÝ

BIÌÍÜÔOQÕRPÝXY
    ÌÍÐÛÛ[X[
BUÔÙ[
    ÌÍÓXZ[ÛØÚÙ]  ÌÍÜÔJB[[Â[ÈÝ]J
BIÌÍÑ]OUÔXÝ    ÌÍÓXZ[ÛØÚÙ]

BTÛY
JBRY    ÌÍÑ]IÉÝÉ][ÝÉ][ÝÈ[BSÙÐÞ
    ][ÝÒ[ÈÛHÙ][ÝË    ÌÍÑ]JBQ[Y[[

Run the server at the server computer. Change the IP address to the server's ip in the client script and then run it. You can send commands like: ipaddress, username, etc. The script will tell you that info from the server comp.

I'm sorry I can't really help you but I'm using someone else's computer.

Share this post


Link to post
Share on other sites
2words4uready

Thanks for the reply but i would like someone to tell me whats wrong with the code so that i can fix it.

EDIT: Lots of typos

Edited by 2words4uready

READ BEFORE POSTINGMy UDF'sMessagesYou say plz because its shorter than please. I say no because its shorter than yes.Join My Website

Share this post


Link to post
Share on other sites
Nahuel

Well just from looking at it I can find many weird things. Like:

Select
    Case Run($exe2)
    EndSelect

Run($exe2) will always be called. And what is $exe2??

I'm not familiar with the TCPFuncs.au3 include. Have you even tried mine? Just modify it and it'll do what you want.

Why close the connection every time?

I made some modifications to yours (well, pretty much everything. And now you can run programs at the server and send messages too)

SERVER

TCPStartUp()
$MainSocket = TCPListen(TCPNameToIP(@computername), 7000,  100 )
If $MainSocket = -1 Then Exit
While 1
    $ConnectedSocket = TCPAccept( $MainSocket)
    If $ConnectedSocket >= 0 Then
        msgbox(0,"","connected",1)
        ExitLoop
    EndIf
Wend
While 1
    $Message=TCPRecv($ConnectedSocket,2048)
    Sleep(25)
    If $Message<>"" Then
                If StringInStr($Message,"/run") Then
                    $exe2=StringSplit($Message,"/run",1)
                    MsgBox(0,"",$exe2[$exe2[0]])
                    Run($exe2[$exe2[0]])
                    ContinueLoop
                EndIf
                If StringInStr($Message,"/msg") Then 
                    $msg=StringSplit($Message,"/msg",1)
                    MsgBox(0,"Message",$msg[$msg[0]])
                EndIf
    EndIf
WEnd

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  

×