Question data transmitting to IP device

jcballo16

Member
Joined
Nov 13, 2019
Messages
11
Programming Experience
Beginner
good morning,

I'm new here, I've got some question, I have a DEVICE that have an IP ADDRESS, I need to get the data that transmitting to that device
I need help on how to do it.

Thank you.
 
If you're trying to connect to the device, you should look at the TcpClient and/or Socket classes. The first is a simplified wrapper for the second. If the device needs to connect to your machine, look at the TcpListener class.
 
If you're trying to connect to the device, you should look at the TcpClient and/or Socket classes. The first is a simplified wrapper for the second. If the device needs to connect to your machine, look at the TcpListener class.
Thank you and I will check my Codes.
 
What is the other device, and how is it connected? Usb, Lan, Wireless, explain?
It connected through LAN, there is no USB its a PLC device this device transmit a data if you tap 1 of those button sir. It will transmit a data, and that data I need to get it through textbox etc.
 
You will then need to know the port of the device.

Once you know the IP of the device, you can likely acquire that through ipconfig /all in cmd. Or use the powershell equivalent, which is more detailed.

You will need a TCP listener. Can be acquired from the link above.
Set the IP/Port, declare a new TCPListener(Address, port)

You then start the listner by calling Start(); on your TCPListener

Then you would likely create a byte array and execute a your listener in a constant loop.
Create a fail-safe should you want to exit the loop, a bool value perhaps where your UI can set the bool true or false per each click. You should note, you would also want your while loop running on a new thread to enable you to interact with your UI, otherwise it will freeze.

Inside the loop you need to access a tcp client, and this client will also need access to the NetworkStream which you also need to define. From here, you would want to read all the bytes into an array and you might be required to do this in another loop. That will be two loops, one nested. Your nested loop will read the data with ASCII encoding, and from the encoding stream, you would simply write out the data.

Now, If you read over the links above, you will see all of the words I used here are referenced there for you in the provided docs. So you shouldn't have any problems trying what I recommended and posting your code up if you get stuck.

It's pretty straight forward.
 
It connected through LAN, there is no USB its a PLC device this device transmit a data if you tap 1 of those button sir. It will transmit a data, and that data I need to get it through textbox etc.
I don't understand. In your original post you were asking how to transmit data to the the device, but in your reply above, you are saying that the device will be the one that will be transmitting data. This makes a difference between you needing a TcpClient to be a client of the device acting as a server, or if you need a TcpListener so that you'll the server for the device acting as a client.

Or is the idea for you to act as a client of the device, and once you are connected, the device will send data to you?
 
Regardless if its a stream going in or out, you will need to read it.

One other thing I didn't mention, is that you might also be faced with a blocking exception due to the port already being in use especially if your device can already listen for traffic. Take that into account too.
 
I don't understand. In your original post you were asking how to transmit data to the the device, but in your reply above, you are saying that the device will be the one that will be transmitting data. This makes a difference between you needing a TcpClient to be a client of the device acting as a server, or if you need a TcpListener so that you'll the server for the device acting as a client.

Or is the idea for you to act as a client of the device, and once you are connected, the device will send data to you?
Oh sir sorry for that if you misunderstood me. All I wanna know is I need to connect that device that's all I'm sorry sir.

Regardless if its a stream going in or out, you will need to read it.

One other thing I didn't mention, is that you might also be faced with a blocking exception due to the port already being in use especially if your device can already listen for traffic. Take that into account too.
Ok sir Thank you.

Its too hard because its my first time to encounter this kind codes. So that's why I really need help thank you.
 
Its too hard because its my first time to encounter this kind codes. So that's why I really need help thank you.
If this is your first time doing any kind of networking code, I highly recommend going up the learning curve first where you you control both the client and server. Only after you've got a good handle on how that interaction works, then start doing the one sided work involved here where your code will either be the client or the server.

For a quick overview of what you need to learn, consider reading these:

The links above are for the low level Sockets APIs. Although they will get you down into the weeds with details, they also teach some important concepts, specially if you follow the synchronous code examples. From there you should just look at the code examples from the aforemention TcpClient and TcpListener classes.
 
If this is your first time doing any kind of networking code, I highly recommend going up the learning curve first where you you control both the client and server. Only after you've got a good handle on how that interaction works, then start doing the one sided work involved here where your code will either be the client or the server.

For a quick overview of what you need to learn, consider reading these:

The links above are for the low level Sockets APIs. Although they will get you down into the weeds with details, they also teach some important concepts, specially if you follow the synchronous code examples. From there you should just look at the code examples from the aforemention TcpClient and TcpListener classes.
Thank you sir.
 
Back
Top Bottom