Recent

Author Topic: can i make server?  (Read 68510 times)

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: can i make server?
« Reply #15 on: October 17, 2017, 11:29:07 am »
All the given alternatives don't have clear examples in them (as far as I can tell).

@shs, Why not just download Synapse and try the examples I gave?
What didn't you understand from them?

Installing Synapse:

Using Synapse package in your project:
  • You need to know that Synapse is not a visual component library so there are no components. You also don't need to recompile Lazarus. You DO need to include laz_synapse in your project under requirements. After that you can use the TClasses etc from the Synapse library to get started.
  • In your project, open the Project > Project Inspector. Choose Add > New requirement.
  • Type synapse and choose laz_synapse and then Ok.
  • Now you can use the example-code you find which use blcksock, TUDPBlockSocket etc. See http://synapse.ararat.cz/doc/help/
  • There are lots of examples using Synapse

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: can i make server?
« Reply #16 on: October 19, 2017, 10:56:19 am »
@rvk
hi i installed it it tried to do the examples you gave but i don't understand it

firstly i don't know what blcksock do
http://synapse.ararat.cz/doc/help/
i checked this but still don't get it

also is this necessary?
Code: Pascal  [Select][+][-]
  1.  procedure TForm1.OnStatus(Sender: TObject; Reason: THookSocketReason; const Value: string);
  2. var
  3.   sReason : String;
  4. begin
  5.   case Reason of
  6.     HR_ResolvingBegin : sReason := 'HR_ResolvingBegin';
  7.     HR_ResolvingEnd : sReason := 'HR_ResolvingEnd';
  8.     HR_SocketCreate : sReason := 'HR_SocketCreate';
  9.     HR_SocketClose : sReason := 'HR_SocketClose';
  10.     HR_Bind : sReason := 'HR_Bind';
  11.     HR_Connect : sReason := 'HR_Connect';
  12.     HR_CanRead : sReason := 'HR_CanRead';
  13.     HR_CanWrite : sReason := 'HR_CanWrite';
  14.     HR_Listen : sReason := 'HR_Listen';
  15.     HR_Accept : sReason := 'HR_Accept';
  16.     HR_ReadCount : sReason := 'HR_ReadCount';
  17.     HR_WriteCount : sReason := 'HR_WriteCount';
  18.     HR_Wait : sReason := 'HR_Wait';
  19.     HR_Error : sReason := 'HR_Error';
  20.   end;

also if i make a server, does it only work for the people who are connected to the same wifi?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: can i make server?
« Reply #17 on: October 19, 2017, 11:22:44 am »
also is this necessary?
Code: Pascal  [Select][+][-]
  1.  procedure TForm1.OnStatus(Sender: TObject; Reason: THookSocketReason; const Value: string);
No, it's not. It's just to clarify for the user what is happening (connection established, read, write etc.)

firstly i don't know what blcksock do
http://synapse.ararat.cz/doc/help/
i checked this but still don't get it
You shouldn't just dive in the technical manual. Just study the example and learn about what it does.
For instance... TUDPBlockSocket is used to create UDP-variable. It can be used to send out message over the network to a specific IP on a specific port. (that's what you specify in UDP.Connect).  UDP.SendString actually sends the data and with RecvPacket you receive data.

blksock is a unit in which TUDPBlockSocket is defined. And like I said... you also need to learn about the terms UDP, TCP, Socket. Did you Google those terms?

also if i make a server, does it only work for the people who are connected to the same wifi?
Normally it only works within the same network. If you want it to work outside your network (i.e. on the internet) you'll need to open up the necessary ports in both routers (which the clients/servers are behind).

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: can i make server?
« Reply #18 on: October 19, 2017, 11:48:52 am »
i watched the video on youtube talking about UDP and TCP and it says TCP is better for texting because  UDP doesn't do retransimissions so some message can get lost.

but why is UDP used in the example?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: can i make server?
« Reply #19 on: October 19, 2017, 11:54:56 am »
i watched the video on youtube talking about UDP and TCP and it says TCP is better for texting because  UDP doesn't do retransimissions so some message can get lost.

but why is UDP used in the example?
You can easily make the same example use TCP.

You can use UDP but UDP does not guarantee that the message is received. You can however implement an acknowledge package yourself (send OK+messagenumber back to the sender). If the sender does not receive it, it can retransmit the message.

The advantage of UDP is that you can broadcast message to the entire network so that all clients listening on a specific port receive that message. With TCP you would need to establish a connection with each client.

Also, with TCP you'll need to know the IP of the client (other side) to establish a connection. With UDP (broadcast) you can use UDP and in the message-package you can put a client-name. All clients will receive the same package but only act if their client-name is in the package. This is not really secure (because everyone receives the message) but is security is an issue you should build in some encryption too. But that's beyond the scope of your question.

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: can i make server?
« Reply #20 on: October 19, 2017, 12:17:59 pm »
thank you for clear explanation

i googled socket and i kinda don't get it. it say socket is connection between 2 programs, so it doesn't work if programs are more than 3? also does udp need socket to make a server?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: can i make server?
« Reply #21 on: October 19, 2017, 12:27:42 pm »
i googled socket and i kinda don't get it. it say socket is connection between 2 programs, so it doesn't work if programs are more than 3? also does udp need socket to make a server?
Yes, for UDP you also need a socket.
For TCP you can only connect to one computer per socket. If you need to connect to multiple computers you'll need to use multiple sockets. The upside of UDP is that you can use one socket to broadcast one message to multiple computers listening to it.

Quote
In the standard Internet protocols TCP and UDP, a socket address is the combination of an IP address and a port number, much like one end of a telephone connection is the combination of a phone number and a particular extension. Sockets need not have an address, for example, for only sending data, but if a program binds a socket to an address, the socket can be used to receive data sent to that address. Based on this address, Internet sockets deliver incoming data packets to the appropriate application process.
https://en.wikipedia.org/wiki/Network_socket

So a socket is just a other name for connection (UDP or TCP or otherwise).

For TCP connections the connection is really from IP <-> IP. That's why it's guaranteed that the message is received correctly. The underlying TCP-protocol handles the acknowledgements of packages to eachother.

For UDP you just send out a package over the network with address and port and forget about it. It's up to the client to be listening. If it is not, then the package just gets lost. And if you really want to make sure the package is received you can do the acknowledgements yourself.

So sockets are just a means by which you "begin" using UDP or TCP.
https://docs.oracle.com/javase/tutorial/networking/sockets/definition.html
Quote
A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to.
« Last Edit: October 19, 2017, 12:30:23 pm by rvk »

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: can i make server?
« Reply #22 on: October 19, 2017, 12:30:14 pm »
how do i know if the client is listening or not?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: can i make server?
« Reply #23 on: October 19, 2017, 12:32:34 pm »
how do i know if the client is listening or not?
That depends.

In a local network you can do a broadcast on UDP and everyone who is listening can answer back.

For TCP you'll need one "server" which is always listening. Clients can connect to that server via TCP. That way the server knows who the clients are.

It all depends on what kind of messaging system you want to make.

(over the internet you can't use the broadcast because you can't broadcast one message to every computer on the internet. There you must use a client-message and record that the client is active)

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: can i make server?
« Reply #24 on: October 19, 2017, 12:48:50 pm »
Quote
(over the internet you can't use the broadcast because you can't broadcast one message to every computer on the internet. There you must use a client-message and record that the client is active)

i don't really get what this means
what is the difference between internet and local network?

i just want certain people to connect my server on the internet

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: can i make server?
« Reply #25 on: October 19, 2017, 01:12:29 pm »
i just want certain people to connect my server on the internet
In that case it is better to forget about UDP because the stability of the connection is much lower.

You'll need to create a server program where every client checks in.
You'll need to make the server listen on a specific port and you need to open up that port on your router.
If you don't know how you can open up a port on your router you'll need to learn about that first.

You'll also need to learn about what your internal IP (on the local network) and external IP is and what the difference is.

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: can i make server?
« Reply #26 on: October 19, 2017, 01:30:09 pm »
so i have to use TCP?
and how many programs should i make then?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: can i make server?
« Reply #27 on: October 19, 2017, 01:49:35 pm »
One server (which you run on your computer 24/7 or at times your client need to connect).
The server opens a socket and listens on a specific port.
In the router you need to forward that port to your internal IP address.

One client. The client opens a socket and connects to your internet IP adres (your external address) and your port. The connection is then established.

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: can i make server?
« Reply #28 on: October 19, 2017, 02:14:40 pm »
wait do i get to choose the port?
just random number?

so i need to make 2 different application?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: can i make server?
« Reply #29 on: October 19, 2017, 02:19:30 pm »
wait do i get to choose the port?
just random number?

so i need to make 2 different application?
Yes you need 2 different applications.

You can just pick a random number but you need to use the same number in the client app and you need to forward that port in your router if you want to connect from the internet to it.

But when you want to have multiple connection at the same time it becomes much much more difficult because you would need to work with threads.

 

TinyPortal © 2005-2018