Marathon24 finished a few weeks ago and my team has received a chance to go to the Grand Finals. However reading carefully the rules described, I saw the following thing :
Communication is realized with text commands sent through the TCP/IP protocol, described in details in the problem statement.
I also checked problems from last year and indeed, they give you a set of commands you can send through TCP/IP to communicate with the contest system.
Now the problem is that none of our team has any clue how this whole TCP/IP communication works. I would really appreciate it if someone could explain how it works and how to create a C++ code that communicates through TCP/IP, as I believe that's what you are expected to do during the competition.
Thank you in advance! :)
Edit: Turns out we can't participate due to complications with travelling, however the question is still valid! :)
I should say it's very easy if you use Java (or C#, as it's almost the same): just find the class Socket and its usage
Is it possible to do it in C++? If it isn't, I suppose C# is close enough but C++ would still be more comfortable. Also, is it possible to link me to sample implementation or something? We really have no idea how to do any of it.
You can make a link between Java and C++. Java reads packets from TCP and passes it to a standard input stream of an external program (C++). External program does calculations and writes output to a standard output stream, which is then picked up by a running Java process.
You can use boost in C++.
I used it at Deadline24.
You just create something like your cin/cout stream and use it as you want.
https://github.com/glapul/marathon_lib
wrapper.* and ctcpfwd.*
it may contain bugs.
As I rememberو using
bash
there is some way to pipe I/O of some command into another command, so they read each others I/O and respond to each other. Using this you can pipe the commandsnc localhost 5555
and./a.out
together, assuming your programs binary file isa.out
and TCP server is running onlocalhost:5555
.I don't remember the syntax, so if anybody knows how to do that, please let us know. :)
Finally I found the way to do it, I mailed the person who told me this first and got a reply.
For the above example, you can run your code with the following bash command:
This way you write a simple code without TCP/IP stuffs, like every other query based or interactive problem in on-line judges, and then you direct the I/O to a socket instead of standard I/O. You can have an eye on what your program sends or receives, by printing into error stream. You might like to read this, to know the details of what I said.
There is another way to do this with something called
fifo
in bash. You can make them withmkfifo
. But I don't have much information about them, so you can google it.Last year during the Marathon24 finals, I knew that there's some way to do this, but I couldn't remember it and it was unfortunate. I just remember that day we did very strange things to communicate with sockets. :D