Jump to content

Instant MESSENGER


 Share

Recommended Posts

Hello All!

I want to made a application who like to an Instant Messenger.

The gui is OK, but I don't know about the technic to use for send and receive messages.

UDP/TCP??

Can you explain me with examples this two fonctionnalities in the server and the client.

Thanks All.

Bye

Link to comment
Share on other sites

I would suggest UDP. UDP packets have less capabilities than TCP but are smaller, simpler and faster than TCPs.

We usually use UDP when we need small and fast packets that we don't care if they reach their destination (i.e. for an intranet application, for gaming etc). TCP ones are usually used when we have big packet size and not a high sending frequency.

If you are going to use your application over the Internet though, I would suggest TCP beyond any thinking.

Also do some research on the internet on this issue.

I.e.: http://www.windowsitpro.com/Article/Articl...0315/40315.html

Link to comment
Share on other sites

Please first read about TCP and UDP, and the native autoit functions. Study the design of my TCP Made Easy thread located here:

http://www.autoitscript.com/forum/index.ph...topic=18738&hl=

And review the server and client script released on ITS Forums. If you do not understand something past that part, then you may ask, I can only give you tools to help you, I cannot magically give you knowledge.

AutoIt Smith

Link to comment
Share on other sites

@Everyone

*Laughs Out Loud*

Here is some general Information:

TCP Meaning (According to Dictionary.com):

http://dictionary.reference.com/search?q=t...trol%20protocol

transmission control protocol

<networking, protocol> (TCP) The most common transport layer

protocol used on Ethernet and the Internet. It was

developed by DARPA.

TCP is the connection-oriented protocol built on top of

Internet Protocol (IP) and is nearly always seen in the

combination TCP/IP (TCP over IP). It adds reliable

communication and flow-control and provides full-duplex,

process-to-process connections.

TCP is defined in STD 7 and RFC 793.

User Datagram Protocol is the other, connectionless,

protocol that runs on top of IP.

UDP Meaning(According to Dictionary.com):

http://dictionary.reference.com/search?q=u...gram%20protocol

user datagram protocol

<protocol> (UDP) Internet standard network layer,

transport layer and session layer protocols which

provide simple but unreliable datagram services. UDP is

defined in STD 6, RFC 768. It adds a checksum and

additional process-to-process addressing information [to

what?]. UDP is a connectionless protocol which, like TCP,

is layered on top of IP.

UDP neither guarantees delivery nor does it require a

connection. As a result it is lightweight and efficient, but

all error processing and retransmission must be taken care of

by the application program.

Examples in AutoIt:

TCP Client Example

Global $MainSocket
Local $MaxLength = 512; Maximum Length Of Text
Local $Port = 1000; Port Number
Local $Server = @IPAddress1; Server IpAddress
TCPStartup()
$MainSocket = TCPConnect($Server, $Port)
If $MainSocket = -1 Then Exit MsgBox(16, "Error", "Unable to connect.")
While 1
    $Data = TCPRecv($MainSocket, $MaxLength)
    If $Data = "~bye" Then
        MsgBox(16, "Session Ended", "Connection Terminated.")
        Exit
    ElseIf $Data <> "" Then
    ; Unconditional Receive
        MsgBox(0, "Received Packet", $Data)
    EndIf
WEnd
Func OnAutoItExit()
    If $MainSocket <> - 1 Then
        TCPSend($MainSocket, "~bye")
        TCPCloseSocket($MainSocket)
    EndIf
    TCPShutdown()
EndFunc  ;==>OnAutoItExit

TCP Server Example

Global $MainSocket = -1
Global $ConnectedSocket = -1
Local $MaxConnection = 1; Maximum Amount Of Concurrent Connections
Local $MaxLength = 512; Maximum Length Of String
Local $Port = 1000; Port Number
Local $Server = @IPAddress1; Server IpAddress
TCPStartup()
$MainSocket = TCPListen($Server, $Port)
If $MainSocket = -1 Then Exit MsgBox(16, "Error", "Unable to intialize socket.")
While 1
    $Data = TCPRecv($ConnectedSocket, $MaxLength)
    If $Data = "~bye" Then
        MsgBox(16, "Session Ended", "Connection Terminated.")
        Exit
    ElseIf $Data <> "" Then
    ; Unconditional Receive
        MsgBox(0, "Received Packet", $Data)
    EndIf
    If $ConnectedSocket = -1 Then 
        $ConnectedSocket = TCPAccept($MainSocket)
        If $ConnectedSocket <> -1 Then
        ; Someone Connected
            TCPSend($ConnectedSocket, "Connected!")
        EndIf
    EndIf
WEnd
Func OnAutoItExit()
    If $ConnectedSocket <> - 1 Then
        TCPSend($ConnectedSocket, "~bye")
        TCPCloseSocket($ConnectedSocket)
    EndIf
    If $MainSocket <> -1 Then TCPCloseSocket($MainSocket)
    TCPShutdown()
EndFunc  ;==>OnAutoItExit

UDP Server Example

Global $MainSocket
Local $MaxConnection = 1; Maximum Amount Of Concurrent Connections
Local $MaxLength = 512; Maximum Length Of String
Local $Port = 1000; Port Number
Local $Server = @IPAddress1; Server IpAddress
UDPStartup()
$MainSocket = UDPBind($Server, $Port)
If @Error <> 0 Then Exit MsgBox(16, "Error", "Unable to intialize socket.")
While 1
    $Data = UDPRecv($MainSocket, $MaxLength)
    If $Data = "~bye" Then
        MsgBox(16, "Session Ended", "Connection Terminated.")
        Exit
    ElseIf $Data <> "" Then
    ; Unconditional Receive
        MsgBox(0, "Received Packet", $Data)
    EndIf
WEnd
Func OnAutoItExit()
    UDPSend($MainSocket, "~bye")
    UDPCloseSocket($MainSocket)
    UDPShutdown()
EndFunc

UDP Client Example

Global $MainSocket
Local $MaxLength = 512; Maximum Length Of Text
Local $Port = 1000; Port Number
Local $Server = @IPAddress1; Server IpAddress
UDPStartup()
$MainSocket = UDPOpen($Server, $Port)
If @Error <> 0 Then Exit MsgBox(16, "Error", "Unable to connect.")
UDPSend($MainSocket, "Connected!")
While 1
    $Data = UDPRecv($MainSocket, $MaxLength)
    If $Data = "~bye" Then
        MsgBox(16, "Session Ended", "Connection Terminated.")
        Exit
    ElseIf $Data <> "" Then
    ; Unconditional Receive
        MsgBox(0, "Received Packet", $Data)
    EndIf
WEnd
Func OnAutoItExit()
    UDPSend($MainSocket, "~bye")
    UDPCloseSocket($MainSocket)
    UDPShutdown()
EndFunc

TCP/IP Introduction:

http://www.yale.edu/pclt/COMM/TCPIP.HTM

UDP Introduction:

http://www.networksorcery.com/enp/protocol/udp.htm

I hope you find this information useful.

AutoIt Smith

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