Jump to content
limelect

Problem with UDPClient

Recommended Posts

I have a software solution but I want to understand and have

a nicer fix.

I have UDPClient and UDPServer

I receive a text from the server with a press of a button on the client.

If I press once I get the text OK Second time I get Zero in the buffer.

I made sure that the server sends the text every time.

So I made a stupid fix that works perfectly.

 

   UDPClient.ReceiveBuffer(Buf);
   if buf[0]=0 then
    UDPClient.ReceiveBuffer(Buf);

 

Any idea why it happens
I read a question about resetting the client buffer.

Further, if I delete the connection and reconnect it works.

But I am not allowed to do so as the connection has to stay with

the right peer number.

 

Share this post


Link to post
5 hours ago, limelect said:

I have UDPClient and UDPServer

Which UDP components, exactly? Indy's?  Someone else's?  Please be more specific.

5 hours ago, limelect said:

If I press once I get the text OK Second time I get Zero in the buffer.

I made sure that the server sends the text every time.

Please show your actual code on both sides.

5 hours ago, limelect said:

So I made a stupid fix that works perfectly.

The only way that makes sense is if the server is actually sending a $00 byte, OR, if you have pre-sized your Buf beforehand and ReceiveBuffer() is not filling it in (ie, is ReceiveBuffer() returning 0 bytes read as its return value?).

5 hours ago, limelect said:

Any idea why it happens

Not without seeing your actual code.

5 hours ago, limelect said:

Further, if I delete the connection and reconnect it works.

UDP is connection-less.  There is no connection to reset.

Edited by Remy Lebeau

Share this post


Link to post

@Remy Lebeau First thanks.

2 hours ago, Remy Lebeau said:

Which UDP components, exactly? Indy's?  Someone else's?  Please be more specific.

Indy's.

 

2 hours ago, Remy Lebeau said:

Please show your actual code on both sides.

It is so simple

UDPClient.Send('#2');

server response

         mytext := StringToBytes(s);
          UDPServer.SendBuffer(ABinding.PeerIP, ABinding.PeerPort, mytext);

2 hours ago, Remy Lebeau said:

The only way that makes sense is if the server is actually sending a $00 byte,

I am profesional to exclude that. checking with a brp on the server 

and seeing the problem in the client

 

Most of the time strings are very short.

But in that case, the string is a bit longer like maybe 100 characters.

And I expect to receive even longer strings.

 

It seems something within the receiver (client) as 

The server works perfectly.

 

 

Share this post


Link to post

@Remy Lebeau First thanks.

3 hours ago, Remy Lebeau said:

Which UDP components, exactly? Indy's?  Someone else's?  Please be more specific.

Indy's.

 

3 hours ago, Remy Lebeau said:

Please show your actual code on both sides.

It is so simple

UDPClient.Send('#2');

server response

         mytext := StringToBytes(s);
          UDPServer.SendBuffer(ABinding.PeerIP, ABinding.PeerPort, mytext);

3 hours ago, Remy Lebeau said:

The only way that makes sense is if the server is actually sending a $00 byte,

I am profesional to exclude that. checking with a brp on the server 

and seeing the problem in the client

 

Most of the time strings are very short.

But in that case, the string is a bit longer like maybe 100 characters.

And I expect to receive even longer strings.

 

It seems something within the receiver (client) as 

The server works perfectly.

 

If things are not  stable I will move to a different communication

 

 

Share this post


Link to post

OK thanks

I have written a client-server for testing and it works perfectly

So it might be that something in my huge software does the problem.

So back to the drawing board

Share this post


Link to post

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

×