Jump to content

TCP socket connected to an existing server


 Share

Recommended Posts

thanks for your reaction, please can you help me search for one basic client/server script, because i can't find any. My server and client are two different computers but connected on the small local network.

Thanks for your solution in advance.

Regards

Link to comment
Share on other sites

look in my signature

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

This topic is a joke, like those who don't take the time to make a forum search :dance:

Agreed! I found a great example in the help file alone. Start in the help file. Get that working before you change anything about it so you know your communicating successfully. If your trying to communicate over the network you need to open up ports on your router as well as windows firewall.

Link to comment
Share on other sites

Hi all,

i know it might sought like a joke to some of you, but know i am just a beginner please.

Here is my code, i can send but cannot receive anything, by the way bogQ thanks i have gone through your signature.

;CLIENT!!!!!!!! Start SERVER First... dummy!!

Local $g_IP = "190.16.7.185"

Local $socket

Local $recv

Local $status

Local $ConnectedSocket

Local $szIP_Accepted

; Start The TCP Services

TCPStartup()

; Attempt to connect to SERVER at its IP and PORT X

$socket = TCPConnect($g_IP, 50000)

MsgBox (0, "Socket", "Socket: " &$socket)

If $socket = -1 Then Exit ;Initialize a variable to represent a connection > -1

While (1)

$status = TCPSend($socket, "StringToBinary(ap_ca_version)")

If $status = 0 Then

MsgBox(0, "ERROR", "Error while sending TCP message: " &@error)

Else

MsgBox(0, "Sent", "mgn sent is: " &$status)

Exit

EndIf

Do

$srcv = TCPRecv($socket, 2048)

; convert from UTF-8 to AutoIt native UTF-16

$recv = BinaryToString($recv, 4)

MsgBox(0, "Received", "Message received: " &$recv)

Until $recv <> ""

ExitLoop

WEnd

TCPCloseSocket ($socket)

TCPShutdown()

regards

Link to comment
Share on other sites

Hi,

With your code (using local IP) you need two computers, If you want to test it on your own computer you have to use the loopback which is : 127.0.0.1

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Hi,

I have tried that with 127.0.0.1 but i could not still receive my sent message, I believe the problem has something to do with TCPRecv. My message box "MsgBox(0, "Received", "Message received: " &$recv)

" is executed but contained no message inside. looking forward for your assistance.

regards

Hubert24

Link to comment
Share on other sites

your code looks wrong in some cases

your dooing:

$srcv = TCPRecv($socket, 2048)

$recv = BinaryToString($recv, 4)

so your requesting binary from noting

second you're never gona exit loop cos $recv is always NULL and even if you do receive something your msgbox will display nothing.

And your msgbox shud stand outside of Do Untill loop in this case and you shud use msgbox only if you intend to exiting from program after it.

And your error check (If $status = 0 Then Else) for not error is using msgbox, that will pause the script, pls don't use msg boxes for something like that when your working with TCP, use ConsoleWrite while your testing, and gui commands if and when your finalizing your program.

Edited your code so that you can try something like this

;CLIENT!!!!!!!! Start SERVER First... dummy!!
Local $g_IP = @IPAddress1
Local $socket
Local $recv
Local $status
Local $ConnectedSocket
Local $szIP_Accepted
; Start The TCP Services
TCPStartup()
; Attempt to connect to SERVER at its IP and PORT X
$socket = TCPConnect($g_IP, 1018)
If $socket = -1 Then Exit ;Initialize a variable to represent a connection > -1
While 1
    $status = TCPSend($socket, "StringToBinary(ap_ca_version)")
    If @error Then
        MsgBox(0, "ERROR", "Error while sending TCP message: " &@error)
        ExitLoop
    Else
;        MsgBox(0, "Sent", "mgn sent is: " &$status)
    EndIf
    Do
        $recv = TCPRecv($socket, 2048)
    Until $recv
    $srcv = BinaryToString($recv, 4)
    MsgBox(0, "Received", "Message received: " &$srcv)
    ExitLoop
WEnd
TCPCloseSocket ($socket)
TCPShutdown()
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Thanks a lot Br, FireFox. Infact you are very helpful. I could have a rest now. once more thank you.

Please permit me ask this question, what if i have two computers, one is my server with IP address 192.168.1.1 and the other is my client with ip address 190.16.7.185.

how can i send and receive via TCP?

will be grateful for your help once again

Link to comment
Share on other sites

You're welcome :)

Always the same rule (except for same computer test) : Local IP for the server (here 192.168.1.1) and server public IP for the client (available with _GetIP).

But I doubt that the serv address is 192.168.1.1, because for me it's my box. (available with @IPAddress1)

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Hi Br, FireFox,

I have tried it the way you requested but it doesn't work. On same PC, I can use just the @IPAddress1 instead of 127.0.0.1 and it works perfectly, but if I try to use 2 computers, one with @IPAddress (server) and the other with _GetIP() (client), it doesn't work even if I try @IPAddress1 or _GetIP() on both computers it still does not work. Could you please look at it again?

To make myself more clear, I have two computers, one is server and the other is client, how can i send in both directions via TCP sockets?

I will be grateful to hear from you.

Best regards

Hubert

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