[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

I just failed a job interview /g/. They asked me to write a program

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 44
Thread images: 3

I just failed a job interview /g/.
They asked me to write a program (they recommended in Python, but would accept any language) that:
the client:
accepts a host and port number from the command line
Requests the Quote of the Day from the specified host (different network) over UDP
Prints the resulting quote
only accepts responses from specified server
and times out after 10 seconds

The server should:
accept a port number from the command line
Receive requests from any address
Reply to requests with the Quote of the Day

I've scoured the internet, and I haven't found much except it's outdated, and port 17 is important.

Does anyone know how to do this?
>>
>>60040182
They also asked me to do it over TCP as well--couldn't figure that one out either
>>
>>60040182
Does python not have a sockets library of some kind?
>>
>>60040432
It does
Import sockets I think
Import sys is also needed
>>
Don't ask here, we don't want more Indians writing shitty code. If you can't do it maybe you're not up for the job.
>>
>>60040621
Everyone who knows how to do it at one point didn't at an earlier point.
Plus you obviously have no idea what's being discussed. There's no market for Indians that can do an outdated qotd.
>>
>>60040182
this is a joke right?

literally read up on your language's socket lib.

worst case you have to use some line buffer reader on top of your socket
>>
>>60040182
Give it back Jamal
>>
>>60040182
Should have wrote it in Rust, OP.
>>
>>60040182
This is covered in the book Blackhat Python. Maybe you should read books
>>
ITT:
>I've applied for a job clearly out of my league and failed

So what?
>>
>>60040871
I think I have that book let me check
>>
>>60040877
So I want to learn so it's not out of my league.
Such defeatist attitudes here.
>>
File: python_programmer.jpg (40KB, 425x600px) Image search: [Google]
python_programmer.jpg
40KB, 425x600px
>>60040871
>Blackhat Python
>needing to be a blackhat to open a fucking socket
What a joke. You python guys suck.
>>
>>60040989
This board is full of NEETs who actually have no idea what they're doing bro. Sorry it didn't work out for you, I can barely read code so I'm not useful but I was looking forward to someone implementing this here as well so I could learn a thing.
>>
>>60040989
read up on sockets and network protocols in your language of choice. If you don't even have the drive to work this kind of shit out yourself there is literally no hope for you.
>>
>>60040761
>Everyone who knows how to do it at one point didn't at an earlier point.
... and he took some time to research it and read the documents if they was not an idiot.
>>
>>60040182
why udp? are those guys retarded?
>>
How long did they give you? Were you allowed to google stuff?
>>
>>60041460
Why sockets instead of HTTP? It's just a fucking quote...

Probably they wanted to see how he implements a reliable channel over UDP.
>>
>>60041216
Thanks dude. Unfortunately you're correct.
>>60041240
I have. There's a lot of material, I'll post what I've tried in just a second

>>60041460
They wanted both over udp and tcp. (In different qotds of course)

>>60041492
It was quickly obvious I didn't know. I wasn't allowed to Google it, but I did when I went home, and there's very little as to how to actually do it.

Only leads I have is the python socket library, and port 17.
>>
>>60041564
HTTP is TCP moron.
>>
>>60041427
>if they was not an idiot
what did he mean by this?
>>
>>60041569
OK I have 3 files:
import socket
import sys

def main():
#Get a socket using the IPv4 address
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dest_ip = input("Enter the server ip:")
dest_port = int(input("Enter the server port #:"))
dest_add = (dest_ip, dest_port)
sock.connect(dest_add)

try:
message = 'Message sent.'
print('Sending message')
sock.sendall(message.encode())
received = 0
needed = len(message.encode())
while received < needed:
data = sock.recv(16)
received += len(data)
print(sys.stderr, 'received "%s"' % data)
finally:
sock.close()
if __name__ == '__main__':
main()
#end py

import socket
import sys

# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

server_address = ('localhost', 10000)
message = 'This is the message. It will be repeated.'

try:

# Send data
print(sys.stderr, 'sending "%s"' % message)
sent = sock.sendto(message.encode(), server_address)

# Receive response
print(sys.stderr, 'waiting to receive')
data, server = sock.recvfrom(4096)
print(sys.stderr, 'received "%s"' % data)

finally:
print(sys.stderr, 'closing socket')
sock.close()

finished = input("Finished?")

#end second py from client

#server py in next post

>>60041564
Quote of the day is a method to check connectivity between networks
>>
>>60041689
#server py
import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to the port
#to_ip = input("Enter IP: ")
server_address = ('localhost', 10000)
print(sys.stderr, 'starting up on %s port %s' % server_address)
sock.bind(server_address)
sock.listen(1)

while True:
print(sys.stderr, '\nwaiting to receive message')
connection, client_address = sock.accept()

try:
print(sys.stderr, 'Connected to: ', client_address)
while True:
data = connection.recv(16)
print(sys.stderr, 'received %s bytes ' % len(data))
if data:
connection.sendall(data)
else:
break
finally:
connection.close()


This was all for UDP, I think TCP I'd just need to make a few substitutions somewhere once these files work
>>
>>60041710
>This was all for UDP, I think TCP I'd just need to make a few substitutions somewhere once these files work
disregard that... I had a brain fart
>>
>>60041569
what was the position? network engineer?
>>
>>60041689
>input
You're fired!
>>
>>60041781
I never said i was a good python coder kek

>>60041689
>>60041710
this works when I do it locally, but fails when i try to internetwork (yes I changed localhost to the ip)
>>
>>60041826
They asked you to pass the parameters from the command line my man.
>>
>>60041843
shit. would I just do args[1] or argv[1] or something similar?
>>
>>60041881
Yeah, and checking if you have enough args to do what you want.
>>
>>60041632
op is a fag
>>
>>60041899
Also, an obvious follow up would be asking you to handle exceptions and maybe even use something like optparse.
>>
>>60040182
is this a troll thread?
>>
>>60042155
no one can answer it so how much trolling is it really
>>
>>60041689
Please read the board sticky before posting.

>>51971506

Python is a language with semantically important whitespace, so posting without code tags to preserve the formatting is a very bad idea.

>>60041826
>this works when I do it locally, but fails when i try to internetwork
Sounds like the server is behind a firewall/router with closed ports.
>>
>>60044950
>firewall router with closed ports
Oh my god thank you, that might just be it
>>
File: 1453496738720.jpg (57KB, 449x442px) Image search: [Google]
1453496738720.jpg
57KB, 449x442px
what kind of job was this for? What was the description for it?
>>
>>60044950
Also would just the ipv4 address given by entering "ipconfig" into cmd be sufficient? (And the port number of course)
I'll try disabling the firewalls when I get back.
>>60045120
Honestly it was just tech support at a university. They have to deal with several servers, routers, and networks.
>>
>>60045224
Depends on your network setup. That IP may just be the server's address on the local area network, so trying to connect to it will only work if the client is also on the same network. If you're just testing between two computers (server and client) both connected to your router it should be fine without needing to fiddle with firewalls/port forwarding.

Also in what I guess is your server >>60041710 it looks like you're listening on localhost only. Probably simplest to change this to ANY address ("0.0.0.0"), that might also fix your issue.

For big/multi-file source posting I'd suggest you use a pastebin (pastebin.com, paste.installgentoo.com, github gists, etc)
>>
>>60045224

> Honestly it was just tech support at a university.

And this is where your lies unravel. I was suspicious when I read that this was asked in a job interview, mainly because there is a lot to consider in the requested program that could add up to a lot of programming time which no one wants to sit around waiting for you to figure out. Come on, command line? There's too much to go wrong for an interview, it's too much, even for a software engineering position...but tech support?

***Congratulate OP, everyone, on his/her social hacking skills. Fully knowing how poorly this board looks down on people looking for homework help, they tricked you into doing for them!***
>>
>>60040182
So they basically asked you to write a command line task and a server-side API.
I have no idea how do you make server scripts in Python, but it shouldn't be too hard.

Port 17 is not actually "important". It's just a commonly used port for the purpose. When you're setting up the server, you can use whatever port you want (unless it's already in use).

So you need:

1) Make a UDP request to a specific URL.
2) Return specific data from the response
3) Set up a listener on a specific url:port
Optionally: Set up port forwarding, so the client doesn't have to input port manually.

A listener is literally a controller action that's triggered by external requests and is set up to process them.

That's assuming your server works in MVC. Google how to do these things in Python and you're done.
>>
>>60045794
>could add up to a lot of programming time
If we talk about Ruby on Rails, I can make you a setup in less than 20 minutes.
Thread posts: 44
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.