• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

UDP connection

I have an application that needs to recieve UDP Calls.  On the visual control in delphi I set the remote and local host properties to "LocalHost" and the local port to 44966 and the remote port to 44967.

Then using a sample application from http://www.torry.net/vcl/internet/sockets/tcp_udp.zip I try to send some text to my application with no success. I simply get no response on either of the applications trying to communicate

Any help?
0
Willemvanzyl
Asked:
Willemvanzyl
  • 3
  • 2
2 Solutions
 
Geert GOracle dbaCommented:
you need 2 different computers as the port is blocked when reading or writing
it's a 1 way communication port

this is the sending of the UDP message

var
  Recipient,SendText: string;

Recipient := 'otherpc@44967';
SendText := 'Message';

Udp := TIdUDPClient.Create(Nil);
try
  with Udp do
  begin
    Host := Copy(Recipient, 0, Pos('@', Recipient) -1);
    Port := StrToInt(Copy(Recipient, Length(Host) + 2, Length(Recipient)));
    Send(SendText);
  end;
finally
  FreeAndNil(Udp);
end;

this is the receving part:
place IdUdpServer on form
UDP_RECEIVER = TIdUdpServer
UDP_RECEIVER.Port := 44967;

procedure TForm1.UDP_RECEIVERRead(Sender: TObject; AData: TStream; ABinding: TIdSocketHandle);
var
  S: TStringStream;
  Msg: String;
begin
  Msg := '';
  if AData.Size > 0 then
  begin
    s := TStringStream.Create('');
    try
      S.CopyFrom(AData, AData.Size);
      Msg := Trim(S.DataString);
    finally
      FreeAndNil(S);
    end;
  end;
  if Msg <> '' then
    ShowMessage(Msg);
end;
0
 
WillemvanzylAuthor Commented:
...some more background

The Sender is a windows Service that can either be on a server or on the local PC itself. The process works as follows:

Service (Sender) intercepts a print job, and with UDP, notifies a Popup app (reciever), the popup app displays a form that the user has to complete, and then sends a UDP message back to the service to either continue the print job or cancel it.

Wil try out your sample code, thanx
0
 
JohnjcesCommented:
I am not certain why you are using two different ports for your UDP transmission.

As Geert points out in his sample, the listening and transmitting ports must be the same port.

If you have a UDP Client Socket and UDP Server Socket, they have to be using the same port. Sounds like you are using different ports for different tasks. Make certain that each task uses its correct UDP port.

I have never had a problem using a Client and Server UDP socket on my local host for local testing. UDP is one way, so as an example use port 45678 from client to server and for two way, an additional client and server socket on port 45679 for the reverse communication.

I hope that made some sense.

John
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
WillemvanzylAuthor Commented:
This is my first UDP development, so me and my co developer are real beginners in regard to UDP. We did start using the same port and then switched to multiple ports. Thanks for the info regarding this. Will implement and revert
0
 
JohnjcesCommented:
Let us know and don't forget to close the Q.

john
0
 
WillemvanzylAuthor Commented:
sorted thanx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now