Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Networking and Web Programming
»
Connect to another aplication via TCP/UDP
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Just Curious: When has an...
by
Martin_fr
[December 04, 2025, 11:28:44 pm]
[SOLVED] Assembler error ...
by
yurets_z
[December 04, 2025, 11:18:23 pm]
Cannot find Online Packag...
by
dseligo
[December 04, 2025, 10:57:42 pm]
TMSSQLConnection in MacOS...
by
zeljko
[December 04, 2025, 10:29:17 pm]
Compiled package
by
Ed78z
[December 04, 2025, 10:26:14 pm]
ddebian 12 input err!
by
PascalDragon
[December 04, 2025, 09:39:53 pm]
unusual static FPC
by
PascalDragon
[December 04, 2025, 09:38:46 pm]
How to load read large CS...
by
Nimbus
[December 04, 2025, 08:29:24 pm]
Need help converting a C+...
by
MathMan
[December 04, 2025, 07:05:58 pm]
Lazarus IDE problem?
by
BrunoK
[December 04, 2025, 05:52:48 pm]
Possible LMAX Disruptor (...
by
Martin_fr
[December 04, 2025, 05:07:21 pm]
Recomendations for conver...
by
gidesa
[December 04, 2025, 04:40:32 pm]
Qt6 / X11: problem with G...
by
zeljko
[December 04, 2025, 04:18:33 pm]
How to use nested classes
by
440bx
[December 04, 2025, 01:59:08 pm]
Qt6 / X11 session: strang...
by
AlexTP
[December 04, 2025, 01:04:31 pm]
TShellListView empty spac...
by
jamie
[December 04, 2025, 12:20:14 pm]
Tool to create Windos set...
by
marcov
[December 04, 2025, 11:35:30 am]
IDE Watch Window colors (...
by
Martin_fr
[December 04, 2025, 11:23:38 am]
Anchoring controls with d...
by
Martin_fr
[December 04, 2025, 11:20:42 am]
Why this code is working ...
by
Martin_fr
[December 04, 2025, 11:07:08 am]
BalloonHint in Trayicons ...
by
CM630
[December 04, 2025, 10:59:42 am]
[Solved]Lazreport Labels
by
Petrus Vorster
[December 04, 2025, 09:42:38 am]
MouseAndKeyInput ---> To ...
by
n7800
[December 04, 2025, 08:43:08 am]
Hints in TTrayIcon
by
CM630
[December 04, 2025, 08:04:34 am]
Define background color f...
by
Antek
[December 04, 2025, 07:46:15 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Connect to another aplication via TCP/UDP (Read 6408 times)
M[a]nny
Full Member
Posts: 130
Dreamer
Connect to another aplication via TCP/UDP
«
on:
July 21, 2011, 11:20:38 am »
Hello!
I'd like to make application which is able to connect via TCP or UDP to another one. I'm not sure how to do this but i can make it in PHP. The application is Counter-Strike 2D dedicated server. Look at this.
This function execute command. It doesn't return anything.
Code: PHP
[Select]
[+]
[-]
function
send_command
(
$ip
,
$port
,
$rcon
,
$command
)
{
$fp
=
@
fsockopen
(
"udp://"
.
$ip
,
$port
,
$errno
,
$errstr
)
;
if
(
$fp
)
{
$request
=
chr
(
1
)
.
chr
(
0
)
.
chr
(
242
)
.
chr
(
strlen
(
$rcon
)
)
.
$rcon
.
pack
(
"S"
,
strlen
(
$command
)
)
.
$command
;
fwrite
(
$fp
,
$request
)
;
}
}
But this one returns some value (for example list of players etc..).
Code: PHP
[Select]
[+]
[-]
function
send_command_rtn
(
$ip
,
$port
,
$rcon
,
$command
)
{
$fp
=
@
fsockopen
(
"udp://"
.
$ip
,
$port
,
$errno
,
$errstr
)
;
if
(
$fp
)
{
$request
=
chr
(
1
)
.
chr
(
0
)
.
chr
(
242
)
.
chr
(
strlen
(
$rcon
)
)
.
$rcon
.
pack
(
"S"
,
strlen
(
$command
)
)
.
$command
;
fwrite
(
$fp
,
$request
)
;
$ausgabe
=
fread
(
$fp
,
1000
)
;
return
$ausgabe
;
}
}
What should i do to make this in Lazarus? Any ideas would be really appreciated!
Logged
Bad news: Time flies.
Good news: You are the pilot.
Don't try to be perfect, just be unique.
WalterK
New Member
Posts: 48
Re: Connect to another aplication via TCP/UDP
«
Reply #1 on:
July 21, 2011, 03:57:43 pm »
I'm not sure if this is what you're looking for, but there are two small example programs in the rtl documentation under the Connect and fpAccept entries; search for sockcli.pp and socksvr.pp. The rtl pdf is here:
ftp://ftp.freepascal.org/pub/fpc/docs-pdf/rtl.pdf
Logged
Leledumbo
Hero Member
Posts: 8833
Programming + Glam Metal + Tae Kwon Do = Me
Re: Connect to another aplication via TCP/UDP
«
Reply #2 on:
July 31, 2011, 09:23:51 am »
FPC has basic units for this with sockets unit. However, it's much easier to use 3rd party libraries like synapse or lnet. For games, it's better to use lnet because it has full asynchronous connection support.
Logged
Follow this if you want me to answer:
http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F
http://pascalgeek.blogspot.com
https://bitbucket.org/leledumbo
https://github.com/leledumbo
Code first, think later - Natural programmer B)
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Networking and Web Programming
»
Connect to another aplication via TCP/UDP
TinyPortal
© 2005-2018