Recent

Author Topic: Communication between computers on LAN  (Read 16705 times)

julinalex07

  • Newbie
  • Posts: 3
Communication between computers on LAN
« on: May 28, 2015, 08:56:39 am »
Hello Guys,

I was working on a simple program that should be able to communicate to it's sibling program that is installed on another computer in the same lan..
There are only a few differences between these two programs.

I have googling for a few days now, but am not able to find any example or tutorial that is helpful.
I know about synapse and i have already used it for a couple of times for serial port communication but i dont know if it can be used in this case , i don't even know what protocol i should use ,tcp or udp..
or should i save the data to be transmitted onto a file and sent it over ftp....

Any help would be really appreciated


Thanks in advance

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Re: Communication between computers on LAN
« Reply #1 on: May 28, 2015, 09:12:57 am »
Hello julianalex07, as you says ararat synapse should work for it but its seem to be complex. I only have used  it to echo (ping) to other computers in lan..., also i have been using serial for reading info from mobile to test how it works (contacts, imei, ....) (under windows assigning the exact port and with drivers of device previously installed).

I know is not the same, but an alternative is to use an intermediate database server as MariaDB or Postgres, and interchange information among two or more equipments in the local net. It gets easy access from/to all computers in your local net as clients of a server.

I you finally will be able to have two working equipments in net, by example by tpc/ip point to point it will be very interesting for a lot of people.

Best Regards.

Saludos.
« Last Edit: May 28, 2015, 09:15:04 am by jma_sp »
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Communication between computers on LAN
« Reply #2 on: May 28, 2015, 09:52:57 am »
You can definitely use synapse for this. It's not that hard, although transfer via file (smb) might be simpler. A file via ftp is about as much complex/simple as a direct TCP-connection. It all depends on your requirements. If you need to send data back and forth (real-time communication) you should use a TCP-connection. If you just want to push a string to another computer (without knowing 100% if it arrives) you can use UDP.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

julinalex07

  • Newbie
  • Posts: 3
Re: Communication between computers on LAN
« Reply #4 on: May 28, 2015, 07:38:32 pm »
Thanks for the reply guys  :)

I have been using Lazarus for a long time , but i am really new into this networking stuff

I went through the palabre messenger source but it is really complex with hashing , authentication and stuff like that and i don't really understand anything. %)

I thought about using some sort of intermediate storage or db but had no idea about implementing this so left that, if anyone can show me within example it would be really great  ;D

Same with TCP in synapse , if someone can provide an example (simple ones ) or even just steps ( like , create subject , connect to host like that )on how to achieve that , it would be really appreciated guys.


Thanks in advance

Paul Breneman

  • Sr. Member
  • ****
  • Posts: 290
    • Control Pascal
Re: Communication between computers on LAN
« Reply #5 on: May 28, 2015, 08:35:09 pm »
Welcome julinalex07 to the Lazarus forums!

My (biased) recommendation is that you take a look at the TCP/IP stuff in Control Terminal (it uses Synapse): http://ctrlterm.com/
Regards,
Paul Breneman
www.ControlPascal.com

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Communication between computers on LAN
« Reply #6 on: May 28, 2015, 11:54:15 pm »
if someone can provide an example (simple ones ) or even just steps ( like , create subject , connect to host like that )on how to achieve that , it would be really appreciated guys.
I guess all those complete programs are very difficult to decipher. I understand you like a small simple project which shows you how to setup a TCP connection on both end.

I threw something together which does just that (see project attached). For Windows at the moment but converting it to Linux shouldn't be a problem.

First you need a thread for listening for an incoming connection (click the Listen button on one computer). I used a button because for testing on my computer I just used one PC with a connection to 127.0.0.1 (localhost). You would have this on different computers and you could start Listen on both computers without a problem.

On one of the computers you can click Connect. A connection is made to the given-IP. (Of course that computer needs to be "listening".)

Then, after the listening thread sees an incoming message, it signals the main form to create a TCPBlockSocket. That form, in turn, creates a Receiving thread. I tried receiving via a TTimer but that just slows things down. When the receiving thread receives a string it signals the main form to add it to the memo. For sending a string you can just use the just created TTCPBlockSocket. The receiving thread also creates it's own TCPBlockSocket with the socket from the main form.

It kind of looks complex with those two threads but the listening thread is only used for listening for an incoming connection and the receiving thread is used for receiving in the background (otherwise your program is constantly checking for incoming traffic).

(b.t.w. I added blcksock to my project but maybe it's in a different path than yours so you might need to change it)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Communication between computers on LAN
« Reply #7 on: May 29, 2015, 02:03:13 am »
hello,
there is also the Lnet library to communicate between computers on Lan.
1 - Download the library
2 - Install the packages lnetbase and lnetvisual
3 - Open the project examples/visual/tcpudp
4 - Build the project
Now you have a program to communicate on lan. The program can be client or server.
Click on the host button to be server.

Friendly, J.P

« Last Edit: May 29, 2015, 02:05:21 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

julinalex07

  • Newbie
  • Posts: 3
Re: Communication between computers on LAN
« Reply #8 on: May 29, 2015, 06:28:33 am »
Thanks a bunch guys ,
Now i think i can build the program..

Again thanks a lot guys ;) ;) :)

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Re: Communication between computers on LAN
« Reply #9 on: May 29, 2015, 09:44:18 am »
Thanks Jurassic Pork, i will try  Lnet Library in a little project to connect two computers and learn how it works.

Also  Paul Breneman with ctrlterm.com, best began with simple programs and it seems a good example, thanks.

avra palabre-messenger is too complicated to me by the moment but thanks.

I will look if all of then are listed in softare related to lazarus/freepascal.


ulinalex07 What was you planning to create? A simple chat? or a simple game? as an idea you can implement a simple battleship game :)

Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

macmike

  • Jr. Member
  • **
  • Posts: 85
    • Soft-Practice
Re: Communication between computers on LAN
« Reply #10 on: May 29, 2015, 12:30:20 pm »
I'd been thinking of asking a similar question but the incredibly helpful replies in this thread have just answered it for me - thanks :D

Zittergie

  • Full Member
  • ***
  • Posts: 114
    • XiX Music Player
Re: Communication between computers on LAN
« Reply #11 on: June 01, 2015, 09:40:43 pm »
Rvk:  is it possible to talk to android and ios devices this way.  Do you have experience with android development to send msg from phone/tablet to Lazarus App?
Be the difference that makes a difference

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Communication between computers on LAN
« Reply #12 on: June 01, 2015, 10:00:41 pm »
I don't have experience with Android/iOS development but yes, you can communicate over a TCP connection with Android/iOS.

I don't know what you need to use on the mobile-side but any library which does TCP-connection should be able to connect to your Lazarus side. It doesn't matter if you use Synapse or lnet at the Lazarus side.

(But of course if you're outside of your own network you need to configure you router correctly and open up/forward the appropriate ports)

For the Android side:
http://forum.lazarus.freepascal.org/index.php?topic=16001.0
https://www.youtube.com/watch?v=_emMNy2e8JU
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Android-and-network-td4031396.html

(so I gather that for Android you should also be able to use both Synapse and lnet)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Communication between computers on LAN
« Reply #13 on: June 01, 2015, 10:07:31 pm »
I don't have experience with Android/iOS development but yes, you can communicate over a TCP connection with Android/iOS.

I don't know what you need to use on the mobile-side but any library which does TCP-connection should be able to connect to your Lazarus side. It doesn't matter if you use Synapse or lnet at the Lazarus side.

(But of course if you're outside of your own network you need to configure you router correctly and open up/forward the appropriate ports)

I'm looking for any documentation that explains how a server less chat program might work and how a chat application would be set to work over http. If you have any to recommend would be eternally grateful.


For the Android side:
http://forum.lazarus.freepascal.org/index.php?topic=16001.0
https://www.youtube.com/watch?v=_emMNy2e8JU
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Android-and-network-td4031396.html

(so I gather that for Android you should also be able to use both Synapse and lnet)
and indy since android is linux based shouldn't be a problem.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Zittergie

  • Full Member
  • ***
  • Posts: 114
    • XiX Music Player
Re: Communication between computers on LAN
« Reply #14 on: June 01, 2015, 10:09:26 pm »
OK, Thanks.
I let you know what i come up with. In the mean time it works fine on MacOS, Windows and Linux ARM.

See youtube:  https://m.youtube.com/watch?v=ovSGkMuce1Q
Be the difference that makes a difference

 

TinyPortal © 2005-2018