Practice 50 Go Lang Networking Coding Questions, TechnoVlogs

Practice 50 Go Lang Networking Coding Questions


Q1. Write a Go program to create a simple TCP client that connects to a server and sends a "Hello" message.  
  Input:    
  Connect to server and send "Hello"
  Expected Output:  
  "Hello" sent to the server

Q2. Write a Go program to create a simple TCP server that listens on a port and accepts connections.  
  Input:    
  Listen on port 8080
  Expected Output:  
  Server started and listening on port 8080

Q3. Write a Go program to create a UDP client that sends a message to a server.  
  Input:    
  Send "Hello UDP" to the server
  Expected Output:  
  "Hello UDP" sent to the server

Q4. Write a Go program to create a UDP server that listens on a specific port and receives a message.  
  Input:    
  Listen on UDP port 9090 and receive a message
  Expected Output:  
  Message received: "Hello UDP"

Q5. Write a Go program to establish an HTTP server that responds with "Hello, World!" on a GET request.  
  Input:    
  Send GET request to /hello
  Expected Output:  
  "Hello, World!"

Q6. Write a Go program to make a simple HTTP client that fetches the content of a webpage.  
  Input:    
  Fetch "http://example.com"
  Expected Output:  
  Webpage content received

Q7. Write a Go program to create a basic HTTP server that serves a static HTML file.  
  Input:    
  Access http://localhost:8080/index.html
  Expected Output:  
  Static HTML file content displayed

Q8. Write a Go program to create an HTTP server that serves a JSON response on a GET request.  
  Input:    
  Send GET request to /json
  Expected Output:  
  {"message": "Hello, JSON"}

Q9. Write a Go program to create an HTTP client that sends a POST request with JSON data.  
  Input:    
  POST request with data {"name": "John"}
  Expected Output:  
  Server response: "Data received"

Q10. Write a Go program to create a TCP server that accepts multiple connections and prints the messages sent by clients.  
   Input:     
   Client 1 sends "Hello from client 1"
   Client 2 sends "Hello from client 2"
   Expected Output: 
   Received: "Hello from client 1"
   Received: "Hello from client 2"

Q11. Write a Go program to create a TCP server that sends a response back to the client.  
   Input:     
   Client sends "What's the time?"
   Expected Output:  
   Server response: "The time is 12:00 PM"

Q12. Write a Go program to establish an HTTP server that redirects a client to another URL.  
   Input:     
   Send GET request to /redirect
   Expected Output:  
   Redirected to: http://new-url.com

Q13. Write a Go program to create a WebSocket server that sends a message to a connected client.  
   Input:     
   Client connects and receives a message "Hello WebSocket"
   Expected Output:  
   "Hello WebSocket" received by client

Q14. Write a Go program to create a WebSocket client that sends a message to the server.  
   Input:     
   Send message "Hello Server" to WebSocket server
   Expected Output:  
   "Hello Server" sent to the server

Q15. Write a Go program to fetch and display the HTTP headers from a website.  
   Input:     
   Fetch headers from "http://example.com"
   Expected Output:  
   HTTP Headers: {key: value, ...}

Q16. Write a Go program to create a basic HTTP server that handles query parameters in the URL.  
   Input:     
   Access URL /greet?name=John
   Expected Output:  
   "Hello, John"

Q17. Write a Go program to create a simple HTTP server that handles multiple routes.  
   Input:     
   Access URL /home and /about
   Expected Output:  
   Home page content
   About page content

Q18. Write a Go program to create a simple HTTP server that accepts URL parameters.  
   Input:     
   Access URL /user?id=123
   Expected Output:  
   User ID: 123

Q19. Write a Go program to create a server that logs the requests it receives.  
   Input:     
   Access any URL, e.g., /log
   Expected Output:  
   Logged: "Request received for /log"

Q20. Write a Go program to send a basic HTTP GET request with headers.  
   Input:     
   GET request to /header with "User-Agent: GoClient"
   Expected Output:  
   "User-Agent header received"

Q21. Write a Go program to create a basic HTTP server that listens on a custom port.  
   Input:     
   Listen on port 9090
   Expected Output:  
   Server started on port 9090

Q22. Write a Go program to create an HTTP client that handles cookies in the response.  
   Input:     
   Send GET request to /set-cookie
   Expected Output:  
   Cookie received: "sessionID=xyz"

Q23. Write a Go program to create a TCP server that handles multiple client connections using goroutines.  
   Input:     
   Multiple clients sending messages to the server
   Expected Output:  
   Each client message processed concurrently

Q24. Write a Go program to create an HTTP server that responds with a file download.  
   Input:     
   Access URL /download
   Expected Output:  
   File downloaded: "file.txt"

Q25. Write a Go program to create a TCP client that connects and sends multiple messages.  
   Input:     
   Client sends "Message 1", "Message 2", "Message 3"
   Expected Output:  
   Messages received by the server: "Message 1", "Message 2", "Message 3"
   
Q26. Write a Go program to create a TCP server that can handle multiple clients asynchronously.  
   Input:     
   Client 1 connects, sends message "Hi", Client 2 connects and sends message "Hello"
   Expected Output:  
   Messages processed concurrently: "Hi" from Client 1, "Hello" from Client 2

Q27. Write a Go program to create a simple HTTP client that handles redirects.  
   Input:     
   Send GET request to URL that redirects
   Expected Output:  
   Redirected to: new-url.com

Q28. Write a Go program to create a TCP client that continuously sends messages to the server in a loop.  
   Input:     
   Send message "Ping"
   Expected Output:  
   "Ping" sent continuously to the server

Q29. Write a Go program to create an HTTP server that responds with a JSON array.  
   Input:     
   Send GET request to /items
   Expected Output:      
   [{"id": 1, "name": "Item 1"}, {"id": 2, "name": "Item 2"}]

Q30. Write a Go program to create a TCP server that broadcasts a message to all connected clients.  
   Input:     
   Server sends "Broadcast message"
   Expected Output:  
   All clients receive: "Broadcast message"

Q31. Write a Go program to create an HTTP client that fetches and prints the response status code.  
   Input:     
   Fetch URL and print status code
   Expected Output:  
   Status Code: 200

Q32. Write a Go program to create an HTTP server that handles both GET and POST requests.  
   Input:     
   Send GET request and POST request to /submit
   Expected Output:  
   "GET request received", "POST request received"

Q33. Write a Go program to create a WebSocket server that handles multiple clients sending messages.  
   Input:     
   Client 1 sends "Message 1", Client 2 sends "Message 2"
   Expected Output:  
   Server responds: "Message 1", "Message 2"

Q34. Write a Go program to create a simple HTTP client that authenticates using basic authentication.  
   Input:     
   Send GET request with username and password
   Expected Output:  
   "Authentication successful"

Q35. Write a Go program to create a server that tracks the number of incoming requests.  
   Input:     
   Send multiple requests to the server
   Expected Output:      
   Total requests: 5

Q36. Write a Go program to create an HTTP server that supports chunked transfer encoding.  
   Input:     
   Send large content in chunks
   Expected Output:  
   Content sent in chunks to the client

Q37. Write a Go program to create a UDP server that listens on a port and handles incoming messages.  
   Input:     
   Send message to UDP server
   Expected Output:  
   "Message received"

Q38. Write a Go program to create an HTTP client that sends a file via a POST request.  
   Input:     
   POST request with file "data.txt"
   Expected Output:  
   File uploaded successfully

Q39. Write a Go program to create a WebSocket client that listens for messages from the server.  
   Input:     
   Listen for "Welcome" message from the server
   Expected Output:  
   "Welcome" received from the server

Q40. Write a Go program to create a WebSocket server that sends a message to all connected clients.  
   Input:     
   Server sends "Welcome everyone"
   Expected Output:  
   All clients receive: "Welcome everyone"

Q41. Write a Go program to create a TCP client that reads from a file and sends the content to a server.  
   Input:     
   Send content of "file.txt"
   Expected Output:  
   File content sent to the server

Q42. Write a Go program to create an HTTP server that serves a large file for download.  
   Input:     
   Access URL /download/largefile
   Expected Output:  
   Large file downloaded

Q43. Write a Go program to create a TCP client that reconnects to the server on connection failure.  
   Input:     
   Attempt connection multiple times if the server is down
   Expected Output:  
   Successfully connected after retries

Q44. Write a Go program to create a WebSocket server that broadcasts a message to all clients.  
   Input:     
   Server sends "Update message"
   Expected Output:  
   All clients receive: "Update message"

Q45. Write a Go program to create a WebSocket client that sends a message and waits for a response.  
   Input:  
   Send message "Hello" and wait for response
   Expected Output:  
   "Hello" sent, "Response" received

Q46. Write a Go program to create a UDP server that handles both receiving and sending messages.  
   Input:     
   Send and receive messages
   Expected Output:  
   Message sent and received successfully

Q47. Write a Go program to create a WebSocket server that handles client disconnections.  
   Input:     
   Client disconnects
   Expected Output:  
   Client disconnected

Q48. Write a Go program to create an HTTP server that handles multipart form data.  
   Input:     
   Send form data with text and file fields
   Expected Output:  
   Form data received successfully

Q49. Write a Go program to create an HTTP client that supports custom timeouts.  
   Input:     
   Send GET request with timeout of 5 seconds
   Expected Output:  
   Timeout after 5 seconds

Q50. Write a Go program to create an HTTP server that handles various HTTP methods (GET, POST, PUT, DELETE).  
   Input:     
   Send GET, POST, PUT, DELETE requests
   Expected Output:  
   Handled GET, POST, PUT, DELETE requests

Share on Social Media