Jump to content
Sign in to follow this  
mattschinkel

UDP Server - talk to client

Recommended Posts

why not hardcoding the server's ports?

Because the client's port is supposed to be random. For example, the client PC may have more then one client application open at the same time. In your example, the client port must be 251.

However, the server's incoming port (port to listen on), and also it's outgoing source port (what the client will see in a reply packet) must be the same. This is my issue. As I mentioned, DNS servers have both the same. You can even look if you install wireshark.

Matt.

Share this post


Link to post
Share on other sites

when you use UDPOPEN () that connects to the servers IP on the servers PORT. you don't need to know the clients port at all... if you need the client to recv data, then have a UDPBIND within the client script to listen for servers instructions.

why must the server out\in ports be the same? may i ask what you're code looks like, maybe we can alter it so it does what you want.

Share this post


Link to post
Share on other sites

whats wrong with the UDPBind port Param? or UDPOpen port Param?

You specify the ports in those functions to create a socket. (not necessarily needed for udp...)

I told you the problem many times in all my previous messages. If I use Autoit client + Autoit server, everything would be fine, but that is not take case. Therefore UDP must act correctly according to the majority of other languages out there.

I see nobody answered my question about if Autoit is open source. As I did a search, I see that it is no longer BSD license and it is now freeware. It seems that nobody will be able to correct this problem. This is sad. I may have to try the current open source version http://www.autohotkey.com/

It seems that nobody knows anything about networking and nobody wishes to understand my problem.

Matt.

Share this post


Link to post
Share on other sites

G'day Matt

I've been looking thought this exchange and there are a lot of messages to plow through to get to what you want to do. Everyone is trying to help so a step by step would good to get everyone back on track.

My take on it is you want it to work like this from the servers point of view:

  • Recieve Message from Client Incoming Server Port 251.... Outgoing Client Port [Random1]
  • Send Message to client Incoming Client Port [Random1].... Outgoing Server Port 251
Is that correct?

Couple of questions.

Can you get your Client to send from 251 to 251? (please try it before replying!)

It would appear as if your client (we don't know your code) has to listen on many ports OR it listens on the port it sent on [Random1]. Is this correct?

If this is correct why does the server need to send on 251? The client knows exactly who is replying??

If I use Autoit client + Autoit server, everything would be fine, but that is not take case.

Maybe if you gave us a client and server to test then things would move along.

Most of what has been given to you is guess work as they only have half the code to work with.

Create a client specify clearly what you want each to do.... like I have above and see what those trying to help you can do.

Therefore UDP must act correctly according to the majority of other languages out there.

You keep saying that AutoIT doesn't work and every other language does. Show us a code example where it works the way you want it to work.

I see nobody answered my question about if Autoit is open source. As I did a search, I see that it is no longer BSD license and it is now freeware.

It was Open Source back in 2005 (before my time) not now. I think someone stole the code and used it as his own and that is why it is no closed (source). I'm surprise what you didn't find an answer if you did a search. There is a feedback system (to the author) though I've never used it.

It seems that nobody will be able to correct this problem. This is sad. I may have to try the current open source version http://www.autohotkey.com/

One of the problems is to try and work out what you want-vs-need is hard to work out. I've been bakc and forward over this thread and I'm still not sure.

It seems that nobody knows anything about networking

nobody wishes to understand my problem.

1. WRONG! Do a search there is a LOT of knoowledge on this forum. Also the replies show that they DO have knowledge of networking.

:) I've even got a few dusty letters after my name that I got for going to university and learning networking amoungst other things.

2. Well that should eliminate everyone that was trying to help you.

Have you ever thought that the reason "nobody" understands your problem maybe that you are not explaining it so that they can understand it?

If I were you I'd create a client in autoIT (nice and quick) set them up (cleint & server) so they give lots of feedback (port numbers, etc).

Clearly explain what you want to do (port incoming, outgoing, multiple clinets, etc).

Then SHOW the output of the scripts to demonstrate your problem.

That way anyone that wants to help you can play with the scripts to get it working and maybe find you a solution.

Maybe the solution isn't what you think it is.

Good Luck!

John Morrison

Share this post


Link to post
Share on other sites

My take on it is you want it to work like this from the servers point of view:

* Recieve Message from Client Incoming Server Port 251.... Outgoing Client Port [Random1]

* Send Message to client Incoming Client Port [Random1].... Outgoing Server Port 251

Is that correct?

Yes, that is correct.

Can you get your Client to send from 251 to 251? (please try it before replying!)

Yes, I can and it works.

It would appear as if your client (we don't know your code) has to listen on many ports OR it listens on the port it sent on [Random1]. Is this correct?

Yes, client will listen on the port it sent on which is a random port.

If this is correct why does the server need to send on 251? The client knows exactly who is replying?

1. Because the server's port is 251.

2. Why should the server use two different ports?

3. The client will think a different server application is sending data from the same PC on a different port.

4. The client will think it is a different socket because of the above reasons.

5. DNS servers listen and send data on the same port, like a Autoit DNS server should. This is all the proof you need.

Thanks for your help. It is appreciated. You seem to understand. All I am asking for is to be able to specify a "source port" instead of using a random one when the server reply's to the client. It should be an optional parameter when creating a socket.

I do like Autoit and will continue to use it. I doubt that anyone stole code since it was open source at one time.

I could give you sample client code, but I don't think that would help. Even if I fix my client, other client programs can have the same issue.

Matt.

Share this post


Link to post
Share on other sites

Yes, client will listen on the port it sent on which is a random port.

1. Because the server's port is 251.

2. Why should the server use two different ports?

Common practice is that a server will listen on a port (eg 80) and reply on a random port. Like your client does when it sends a message.

I did a quick check with wireshark and it was about 50/50 between sending on same port and useing a random port.

3. The client will think a different server application is sending data from the same PC on a different port.

WHY?

The client is waiting for a reply to a message on a certian port and it's a client initiated the conversation.

Why would it think it is a different server applictaion that the client hasn't even started a conversation with that is replying?

In fact as UDP is connectionless why isn't the client just listening on a particular port (eg 251 or 252) for the reply?

It really depends on the protocol on top of UDP.

4. The client will think it is a different socket because of the above reasons.

5. DNS servers listen and send data on the same port, like a Autoit DNS server should. This is all the proof you need.

Autoit doesn't have a DNS server.

Are you writing a DNS server?

I can see solutions to the precieved problem. It all depends on "what" you are writing, what the client is expecting and the protocol you are using.

At the moment this is a very artificial situation. You've created a client that expects things in a certian way that "at the moment" isn't possible with Autoit.

My guess is you are the only one that has ever needed UDP to have a defined sending port. If you put in a ticket with a good explaination you may get the authors to add the functionality.

This isn't really a fault with AutoIT it is just functionality that hasn't been implemented. Or more to the point made available to the user.

Thanks for your help. It is appreciated. You seem to understand.

All I am asking for is to be able to specify a "source port" instead of using a random one when the server reply's to the client.

It should be an optional parameter when creating a socket.

Well more like it could be an optional parameter.

You should know as a programmer you add all the parameters/options you "think" users will want. To add tomany just confuses users.

Add a ticket to the developers with a good explaination of why it is needed and I'm sure it will be considered.

I do like Autoit and will continue to use it. I doubt that anyone stole code since it was open source at one time.

I don't doubt it at all. It happens all the time.

If you ask around the senior members here you'll find many of them have had "open source" AutoIT code "stolen" by others that claimed it as their own.

I could give you sample client code, but I don't think that would help. Even if I fix my client, other client programs can have the same issue.

I wonder how many clients would have the same issue, it maybe worth investigating if it is an issue. You maybe jumping at shadows?

If a protocol states that the returned message has the same "sender" port then that is a problem if not then there is no problem.

But as I stated earlier UDP is connectionless so it is only the higher layer protocol you lay on top of it that specifies (or not) that the senders port has to be the same.

John Morrison

Share this post


Link to post
Share on other sites

mattschinkel is right. RFC 768 (User Datagram Protocol) specifies that a UDP packet may specify a source port for use by other applications (this is not used by the routing network, but is not described there). About DNS servers, RFC 2181 states that

Replies to all queries must be directed to the port from which they were sent. When queries are received via TCP this is an inherent part of the transport protocol. For queries received by UDP the server must take note of the source port and use that as the destination port in the response.

Conclusion: Using the AutoIt native UDP functions you cannot create a DNS server according to specifications. You can, however, use DllCall or COM to call a library that exposes these methods.

Edit: Clarifying: There is nothing wrong with the current UDP implementation. It doesn't let you do everything you might want, but neither does the implementation of TCP.

Edited by Manadar

Share this post


Link to post
Share on other sites
Try this:
 
Try this:
;;This is the UDP Server
;;Start this first
 
HotKeySet("{ESC}", "quit")
 
; Start The UDP Services
;==============================================
UDPStartup()
 
; Register the cleanup function.
OnAutoItExitRegister("Cleanup")
 
; Bind to a SOCKET
;==============================================
;$socket = UDPBind("192.168.2.2", 251)
$socket = UDPBind("192.168.1.11", 251)
 
While 1
    ;get UDP data from client
$data_array = UDPRecv($socket, 50,1)
$data=data_array[0]
If $data <> "" Then
        
        ;display incomming data
MsgBox(0, "UDP DATA", $data, 1)
        
        ;send a reply message
        MsgBox("", "UDP DATA", "Sending: Hello Client!", 1)
 
 
local $to_send[4]
$to_send=$Socket ;copy all data from socket
$to_send[2]=$data_array[1] ;replace send-to ip
$to_send[3]=$data_array[2] ;replace send-to port
        $status = UDPSend($to_send, "Hello Client! ")         If $status = 0 then             MsgBox(0, "ERROR", "Error while sending UDP message: " & @error)          Exit         EndIf                  ;clear input data         $data = ""          EndIf sleep(100) WEnd Func quit() UDPCloseSocket($socket) UDPShutdown()     exit EndFunc
 
        If $status = 0 then
            MsgBox(0, "ERROR", "Error while sending UDP message: " & @error)
            Exit
        EndIf
        
        ;clear input data
        $data = ""
        
    EndIf
    sleep(100)
WEnd
 
Func quit()
    UDPCloseSocket($socket)
    UDPShutdown()
    exit
EndFunc
 
So you can send UDP-packets from server's udp port 251.
 
Edited by TimurBayan

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...