Sign in to follow this  
Followers 0
Shanheavel

Send and recive from server

5 posts in this topic

#1 ·  Posted (edited)

Hello!

I'm trying to make a client with:

$IP = 91.203.223.59

$Port = 7171

- Send one message (for example "abcdef...") to $IP and $Port,

- Recive one message from $IP and $Port

My script:

$IP = "91.203.223.59" ; Server IP

$Port = 7171 ; Server Port

;==============================================

TCPStartUp()

$PacketData = "Hello server!!!" ; Packet to send

$socket = TCPConnect($IP, $Port)

If @error Then

MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)

Exit

EndIf

TCPSend($socket, $PacketData)

$listen = TCPListen($IP, $Port)

$ConnectedSocket = TCPAccept($listen)

MsgBox(32, $IP, "Recv from server: " & TCPRecv($ConnectedSocket, 2048))

What is wrong?

Edited by Adrian777

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try:

$IP = "91.203.223.59" ; Server IP
$Port = 7171 ; Server Port
;==============================================
TCPStartUp()
$PacketData = "Hello server!!!" ; Packet to send
$listen = TCPListen($IP, $Port)
$socket = TCPConnect($IP, $Port)
If @error Then
MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
Exit
EndIf
TCPSend($socket, $PacketData)
Sleep(1500) ;Just give it some time for the request to cum
$ConnectedSocket = TCPAccept($listen)

MsgBox(32, $IP, "Recv from server: " & TCPRecv($ConnectedSocket, 2048))

Notice the script starts lsitening BEFORe it connects. Maybe speed is your problem.

If not, I need more information and don't forget to port forward.

-Hypoz

Edited by hyperzap

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Share this post


Link to post
Share on other sites

Thanks for reply. Sending is good but receiving doesn't work.

Share this post


Link to post
Share on other sites

Thanks for reply. Sending is good but receiving doesn't work.

Try this then.

$IP = "91.203.223.59" ; Server IP 
$Port = 7171 ; Server Port 
;============================================== 
TCPStartUp() 
$PacketData = "Hello server!!!" ; Packet to send 
$listen = TCPListen($IP, $Port) 
$socket = TCPConnect($IP, $Port) 
If @error Then 
 MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error) 
 Exit 
EndIf 
TCPSend($socket, $PacketData) 
Sleep(1500) ;Just give it some time for the request to cum 

$timeout_timer = Timerinit()
$callout = False
While $callout = False
 $sock2 = TCPAccept($listen)
 if $sock2 <> -1 then
    MsgBox(32, $IP, "Recv from server: " & TCPRecv($ConnectedSocket, 2048))
    exitloop
 endif
$data = TCPRecv($socket, 2048)
 if $data <> "" then
    MsgBox(32, $IP, "Recv from server ON CLIENT SOCKET, NOT SERVER SOCKET: " & $data)
    exitloop
 endif
if TimerDiff(timeout_timer) > 5000 then $callout = True
Wend
if $callout = True then MsgBox(32, $IP, "FAILED: no data or connection on either socket.")

Try that and check you port forwarding and firewall settings on CLIENT.


ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Share this post


Link to post
Share on other sites

Some of the code is wrong; simple syntax; easy for you to fix (not near autoit compiler and stuff)

I can access the server. What is the server? what protocol is it?

what are you trying to do???

I can't help you without that.


ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

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  
Followers 0