Sign in to follow this  
Followers 0
AlmarM

TCP client to client data send

9 posts in this topic

#1 ·  Posted (edited)

Hi,

I found this TCP UDF made by Kip, and I would like to know how to send a file (like a screenshot) via TCP.

Also, I tried to start making the server. But I have no idea how this stuff works, this is my first time using TCP. Could anyone make a basic server example? Much appreciated.

AlmarM

Read next post.

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I kind of managed to make a server with 2 clients, now what I would love to know, how to send a string (for example: Hai!) to the other connected client?

Server

#include "TCP.au3"

$hServer = _TCP_Server_Create(1337, @IPAddress1)

ToolTip("SERVER: Server Created.", 0, 0)
 
_TCP_RegisterEvent($hServer, $TCP_NEWCLIENT, "NewClient")
_TCP_RegisterEvent($hServer, $TCP_DISCONNECT, "Disconnect")
 
While 1
    
WEnd
 
Func NewClient($hSocket, $iError)
    ToolTip("SERVER: Client connected.", 0, 0)
EndFunc
 
Func Disconnect($hSocket, $iError)
    ToolTip("SERVER: Client disconnected.", 0, 0)
EndFunc

Client 1

#include "TCP.au3"

$hClient = _TCP_Client_Create(@IPAddress1, 1337)

ToolTip("CLIENT1: Connected.", 0, 30)

_TCP_RegisterEvent($hClient, $TCP_RECEIVE, "Received")
_TCP_RegisterEvent($hClient, $TCP_DISCONNECT, "Disconnected")

While 1
    
WEnd

Func Received($hSocket, $sReceived, $iError)
    ToolTip("CLIENT1: Received: " & $sReceived, 0, 60)
EndFunc

Func Disconnect($hSocket, $iError)
EndFunc

Client 2

#include "TCP.au3"

$hClient = _TCP_Client_Create(@IPAddress1, 1337)

ToolTip("CLIENT2: Connected.", 0, 60)

_TCP_RegisterEvent($hClient, $TCP_RECEIVE, "Received")
_TCP_RegisterEvent($hClient, $TCP_DISCONNECT, "Disconnected")

While 1
    
WEnd

Func Received($hSocket, $sReceived, $iError)
    ToolTip("CLIENT2: Received: " & $sReceived, 0, 60)
EndFunc

Func Disconnect($hSocket, $iError)
EndFunc

AlmarM :)

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

personaly i'm not familiar with Kip's UDF... though...

TCPSend ($Socket,$Data)

will send it.. and

TCPRecv ($Socket,$MaxLen)

Kip's UDF simplifies it ALOT, but if you want to learn, i have TCP examples in my Sig, using Multiclient method WITHOUT kip's UDF...

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Yeah, but I want to know how to send a string from Client 1 to Client 2, im totally new to this O_O

EDIT:

My 1,000th post, :)

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

*tries to bump*

Noone knows how to send a string like "hello" from a connected client to another connected client?

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Use Cody's advice and look at his examples.

He has a multi-client chat program that allows clients to talk to each other.

By the way, thanks Cody on this same issue a while back. :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Almar... i will take a look through TCP.au3 and try to figure it out and give an example of how.

Edit:

well.

Use _TCP_RegisterEvent() to register an event. These are the possible events to register:

$TCP_SEND - When you send something.

$TCP_RECEIVE - If something is received.

$TCP_CONNECT - When you connect to the server. (Client only)

$TCP_DISCONNECT - When a connection is closed.

$TCP_NEWCLIENT - When a new client connects to the server. (Server only)

now, im not positive but this may be what your looking for

_TCP_Server_Create($iPort, $sIP="0.0.0.0")

_TCP_Server_Broadcast($sData)

_TCP_Server_ClientList()

_TCP_Server_ClientIP($hSocket)

_TCP_Server_DisconnectClient($hSocket)

_TCP_Server_Stop()

_TCP_Client_Create($sIP , $iPort)

_TCP_Client_Stop($hSocket)

_TCP_Send($hSocket, $sText) ;to send!!

_TCP_RegisterEvent($hSocket, $iEvent, $sFunction);make a function when there is Data being recieved.

Edited by CodyBarrett

Share this post


Link to post
Share on other sites

Almar... i will take a look through TCP.au3 and try to figure it out and give an example of how.

Edit:

well.

now, im not positive but this may be what your looking for

_TCP_Server_Create($iPort, $sIP="0.0.0.0")

_TCP_Server_Broadcast($sData)

_TCP_Server_ClientList()

_TCP_Server_ClientIP($hSocket)

_TCP_Server_DisconnectClient($hSocket)

_TCP_Server_Stop()

_TCP_Client_Create($sIP , $iPort)

_TCP_Client_Stop($hSocket)

_TCP_Send($hSocket, $sText) ;to send!!

_TCP_RegisterEvent($hSocket, $iEvent, $sFunction);make a function when there is Data being recieved.

Aah, I think I've got it. First Client1 (or 2, w/e) sends data to the server, then when it comes to the server, it broadcasts it and then send it to Client 2.

I'll play some with this, ill let you guys when im having a problem. Thanks! :)


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

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