Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to comunicate via LAN ? 1

Status
Not open for further replies.

Spent

Programmer
Mar 20, 2003
100
0
0
BG
I am connected in an Local Area Network with some my friends. I want to write an application in my language. With this application we will comunicate with each other. (Something like LanChat).

My question is, what component should I use for the communication.
TclientSocket and TServerSocket are bad decision because I dont whant to use a server.

Is there a component with which to communicate by broadcast(or multicast, not sure about the word),so that no server is needed.
And how can I make the commucotation.It is only a text communication(Chat).

Thanks. I will apriciate any kind of help.


Spent
mail:teknet@mail.orbitel.bg
 
You're attempting to defy the very definition of communication :)

In order for someone to hear what you're saying, they have to be listening (or in computerspeak, be a server). This is what a server does - it listens for other computers wishing to communicate with it.

I recommend using the Indy component set, it's free, and makes it very easy to send simple strings back and forth. You just need the program to have both a server and client component, and then the same program can talk to itself on different computers.

Why is it you don't want to use a server?
 
Griffyn wrote:
Why is it you don't want to use a server?

I dont want to force one of the machines to be turned on 24 hours a day(the server). I thought that all the users are combined in one server and communicate via that server.(like Mirc network)

Through you words I understand that each PC can be a server itself.

But here is my next question:
How an user can see the other servers and send a message to them. Can I send a message to IP 255.255.255.255 and how ?

I am starting think that I need a component to release a free message in the Network
and other that listens the network and catches the messages that are "floating" in the network space. Am I right ?

About Indy Components:
I have heard a lot about them but nerev used them


Spent
mail:teknet@mail.orbitel.bg
 
I've never used a broadcast message. From memory, you don't actually need to broadcast to 255.255.255.255, you can broadcast just to 192.168.0.255 if you want to broadcast just to your subnet. I may be wrong.

Give it a try for sure. I recommend grabbing version 9 from I don't know what version of Delphi you have - Delphi 6 Pro comes with version 8, which is best upgraded.

Use the TidTCPServer and TIdTCPClient components. You'll want to capture the TidTCPServer.OnExecute event to handle the server side of things. Be aware that each connection made to the server component runs in it's own thread (which allows multiple concurrent connections) so you need to make sure you make your code thread-safe. You'll be able to use the WriteString and ReadString commands on these components to give you a painless way to send simple strings between computers.

Actually, the more I think about it, the less I'm sure this will work. the client component is not multi-threaded, and so will only be able to respond to a single server during the initial (and invisible to you) handshaking protocol that happens during a connection. Try searching on for a component that can broadcast. Just use their search tool.

One way around this may be to write a server program that runs on your personal webspace that you have with your ISP. You can write internet applications (i think) in Delphi - I've never done this though. If you can have a server program running that way (and assuming all your users have internet connections), you can have it handle the notification stage, so that as your friend's computers are started, they notify the server that they exist, and will receive a list of IP addresses of any other friends currently online. You could have the clients contact the server every 10 seconds or so to get an update, and the server could timeout an IP address if it hasn't contacted it.

That way, your program running on the PC will have a constantly updating list of valid IP addresses that you can that do the client/server connections that I discussed earlier.
 
But I don't want to use MAIN server program.

I am thinking is there a way to make an application that just "talks" and in the same time it listens if another program has said something.

My main purpose is to aviod client - server connection

I am not very clear.I will explain it like this:

The client -server communication is
client Connects to server
client says a message
client disconnects from server



But I want to make

client Shouts message (in Local Area Network)
server hears the message (in LAN)

And if every program has a client and server like this they would be able to communicate.Because I want to aviod client - server connection.




Spent
mail:teknet@mail.orbitel.bg
 
Well - to summarise what my previous post just said.

- Try using TIdTCPClient to make a broadcast.

- If that doesn't work, search for a broadcast component.

- If that doesn't work, try writing an internet webserver application that will run on a webserver somewhere (and bypassing your requirement that you have a PC on 24 hours a day) that can handle the server side of things so that you don't need to make broadcasts on your LAN.
 
Can I receive broadcast messages with TidTCPServer and how ?

Spent
mail:teknet@mail.orbitel.bg
 
Heya dude! Once I had to deal with an issue smilar to yours, so check this out:
You could use IdUDPServer/IdUDPClient from the Indy group in order to make broadcasting through your network. Make sure you have the BroadcastEnabled property set to true and everything should go well. If you want to broadcast you could use either '255.255.255.255' or '192.168.xxx.255' the last one allowing you to send the data on a specific network segment of your LAN. If you don't handle with just check the examples from your delphi instalation directory refering to the Indy components. Good luck man!
 
Thank you all. I've done it !

Spent
mail:teknet@mail.orbitel.bg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top