TCPSocket Port problem

I’m working on a data logger console app that takes both serial (rs-485) and ethernet (using an ethernet to rs-485 adapter) inputs. If I use just one input, everything works fine and multiple readings are recorded. If both serial and ethernet inputs are used, the serial reads first followed by the ethernet. For the second reading, the serial is fine, then the program hangs in the TCPSocket. Prior to each reading, I configure all the communication parameters. Part of that process is setting any previous parameters to nil. The ethernet to rs-485 adapter I am using is set to port 2006 which I set in the configuration routine. When I stop the debugger prior to the first write, the debugger show the port has been reassigned to something like 51696. When it is time for the second reading, the port is 2006 and the program hangs. The stop button in the IDE won’t stop it, but closing the console app window does. I am hoping someone can explain what is going on with these port numbers and how I can get control of them.

Earlier, I was not setting closing the socket and setting it to nil. The port number was still a random number in the 50000 range and the program still hung. Norman set me straight earlier that this was not related to the ServerSocket that is also in the app. Removing the ServerSocket and everything related to it did not solve the problem.

Which side is sending? Is the meter sending periodically and the program listening? Or is the program polling the meter and the meter responding? Does the meter connect each time and then disconnect?

The meters are dumb slaves that respond when queried.

i do this all the time.

what Ive noticed is that you need to get the string from the dataavailable event into another string or array, then have a thread
that processes it. when i tried to process the data and store it in a db using just the dataavailable event, it was still processing when
more data arrived.

using threads to do the storing away seemed to cure it.

I have a desktop app written several years ago in RB that reads the meters successfully and the reading is all done in a thread. I don’t think I am experiencing the problem Russ saw as all the messages received are less than 40 bytes, but I will try the tread approach from the old program. Thanks for your suggestion.

Solved. An orphaned socket was the cause.

always good to get to the bottom of problems :wink: