Thread Subject: more than one tcp connection

Subject: more than one tcp connection

From: peter

Date: 23 May, 2011 13:42:02

Message: 1 of 5

Hi,
i need to connect different microcontroller by using tcpip.
Is it possible to create some different tcpip objects and connect them simultaneously?

for example:

obj1 = tcpip('192.168.0.1', 100);
obj2 = tcpip('192.168.0.2', 100);

echotcpip('on',100);
fopen(obj1);
fopen(obj2);

... use both connections (receive and sent data)

fclose(obj1);
fclose(obj2);
echotcpip('off');

Thanks for your suggestions and help

Subject: more than one tcp connection

From: Trent Jarvi

Date: 23 May, 2011 14:22:15

Message: 2 of 5


"peter " <petermuellers@online.de> wrote in message
news:irdo7a$5pt$1@newscl01ah.mathworks.com...
> Hi,
> i need to connect different microcontroller by using tcpip.
> Is it possible to create some different tcpip objects and connect them
> simultaneously?
>
> for example:
>
> obj1 = tcpip('192.168.0.1', 100);
> obj2 = tcpip('192.168.0.2', 100);
>
> echotcpip('on',100);
> fopen(obj1);
> fopen(obj2);
>
> ... use both connections (receive and sent data)
>
> fclose(obj1);
> fclose(obj2);
> echotcpip('off');
>
> Thanks for your suggestions and help

Hi Peter,

The syntax is possible. Depending upon your requirements, you may discover
that opening will happen sequentially underneath.

obj1 = tcpip('localhost', 7);
obj2 = tcpip('localhost', 7);
ports = [obj1,obj2];
echotcpip('on',7);
fopen(ports);
...
fclose(ports);
echotcpip('off');

Subject: more than one tcp connection

From: peter

Date: 23 May, 2011 19:37:02

Message: 3 of 5

> Hi Peter,
>
> The syntax is possible. Depending upon your requirements, you may discover
> that opening will happen sequentially underneath.
>
> obj1 = tcpip('localhost', 7);
> obj2 = tcpip('localhost', 7);
> ports = [obj1,obj2];
> echotcpip('on',7);
> fopen(ports);
> ...
> fclose(ports);
> echotcpip('off');
>

Thanks for your response.
I am not sure if I get the point. So you are able to open as much connections as you want, but there is just one (the last opened one) that is active?
How can I change between different connections? I am not sure about using the fopen command a second time.
Is there any possibiility to store data sent by the other (inactive) connections?
For example:

obj1 = tcpip('192.168.0.2', 7);
obj2 = tcpip('192.168.0.3',7);
fopen(obj1);
fopen(obj2);
...
now I want to receive/sent data from/to obj1 and obj2 simultaneously
...
fclose(obj1);
fclose(obj2);

thanks again :)

Subject: more than one tcp connection

From: Trent Jarvi

Date: 23 May, 2011 23:41:46

Message: 4 of 5


"peter " <petermuellers@online.de> wrote in message
news:ired0u$evf$1@newscl01ah.mathworks.com...
>> Hi Peter,
>>
>> The syntax is possible. Depending upon your requirements, you may
>> discover that opening will happen sequentially underneath.
>>
>> obj1 = tcpip('localhost', 7);
>> obj2 = tcpip('localhost', 7);
>> ports = [obj1,obj2];
>> echotcpip('on',7);
>> fopen(ports);
>> ...
>> fclose(ports);
>> echotcpip('off');
>>
>
> Thanks for your response.
> I am not sure if I get the point. So you are able to open as much
> connections as you want, but there is just one (the last opened one) that
> is active? How can I change between different connections? I am not sure
> about using the fopen command a second time.
> Is there any possibiility to store data sent by the other (inactive)
> connections?
> For example:
>
> obj1 = tcpip('192.168.0.2', 7);
> obj2 = tcpip('192.168.0.3',7); fopen(obj1);
> fopen(obj2);
> ...
> now I want to receive/sent data from/to obj1 and obj2 simultaneously ...
> fclose(obj1);
> fclose(obj2);
>
> thanks again :)
>

Hi Peter,

I think I read too much into 'simultaneously' when I gave an example of
opening both ports in one FOPEN.

You can have multiple TCPIP objects in your workspace. Each object may be
opened and closed at any time. The example just showed opening both objects
at the 'same time' in one line of code. In your example, you will need two
remote machines with IP addresses 192.168.0.2 and 192.168.0.3 but it should
work. The example I gave just uses the echoserver on the local host for
testing. Perhaps the following example will help you understand what is
possible:

>> obj1 = tcpip('localhost', 7);
>> obj2 = tcpip('localhost', 7);
>> echotcpip('on',7);
>> fopen(obj1); fopen(obj2);
>> fprintf(obj1,'test1')
>> fprintf(obj2,'test2')
>> fscanf(obj2)

ans =

test2


>> fscanf(obj1)

ans =

test1

>> fclose(obj1);
>> fclose(obj2);


You can try closing the objects and reopening them in various combinations.
The above example shows that you can have two objects open and they are
independant of each other.

Subject: more than one tcp connection

From: peter

Date: 24 May, 2011 12:58:03

Message: 5 of 5

>
> Hi Peter,
>
> I think I read too much into 'simultaneously' when I gave an example of
> opening both ports in one FOPEN.
>
> You can have multiple TCPIP objects in your workspace. Each object may be
> opened and closed at any time. The example just showed opening both objects
> at the 'same time' in one line of code. In your example, you will need two
> remote machines with IP addresses 192.168.0.2 and 192.168.0.3 but it should
> work. The example I gave just uses the echoserver on the local host for
> testing. Perhaps the following example will help you understand what is
> possible:
>
> >> obj1 = tcpip('localhost', 7);
> >> obj2 = tcpip('localhost', 7);
> >> echotcpip('on',7);
> >> fopen(obj1); fopen(obj2);
> >> fprintf(obj1,'test1')
> >> fprintf(obj2,'test2')
> >> fscanf(obj2)
>
> ans =
>
> test2
>
>
> >> fscanf(obj1)
>
> ans =
>
> test1
>
> >> fclose(obj1);
> >> fclose(obj2);
>
>
> You can try closing the objects and reopening them in various combinations.
> The above example shows that you can have two objects open and they are
> independant of each other.
>

Thanks again, you really helped me a lot :)

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com