Super basic client server program

Background:

So, I find myself in a bit of a pickle. I took CS115 about 3 semesters ago and could not take CS215 until this semester due to being way behind in math. During this hiatus from my programming classes, the curriculum changed pretty drastically. My CS115 class taught me about the first 10 chapters of a C++ book which I did fairly well at. The restructuring that took place now has CS115 taking Python only. Now I am in CS215 where they are trying to teach us intermediate C++ based on what we should already know in Python. I already talked to my teacher and advisor about this, but neither of them seem to understand why I am having such a hard time with it. I likened it to only speaking English, then taking a class where they taught you how to speak french, but they only spoke German.

Problem:
So, essentially I was given a code written in Python of a SUPER simple client/server program. 2 seperate files. I need to translate this into a program in C++ that does the same thing. VERY VERY VERY basic client/server that can run between two PCs on a local network, not across networks. I have studied this book front to back for weeks now, I have tried to figure out how to convert the code, I have studied online C++ libraries and I still, for the life of me can not figure it out because everything I see for sockets are meant for network to network as opposed to just LANs. The Python code is 15 lines for the client and 18 lines for the server. All examples and such for C++ I find are upwards of 100+ lines.

ANY help would be great!

Here is the python server code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Save as server.py 
# Message Receiver
import os
from socket import *
host = ""
port = 13000
buf = 1024
addr = (host, port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
UDPSock.bind(addr)
print ("Waiting to receive messages...")
while True:
    (data, addr) = UDPSock.recvfrom(buf)
    print ("Received message: ",data)
    if data == "exit":
        break
UDPSock.close()
os._exit(0)


and the client code for python:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  # Save as client.py 
# Message Sender
import os
from socket import *
host = "10.34.167.64" # set to IP address of target computer
port = 13000
addr = (host, port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
while True:
    data = input("Enter message to send or type 'exit': ")
    UDPSock.sendto(data.encode('utf-8'), addr)
    if data == "exit":
        break
UDPSock.close()
os._exit(0)


and here is the pittance of a client code I have...the problem is I started delving into things he doesn't want us using yet and he is not very helpful.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include <iostream>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>


using namespace std; 

int main()
{
	int CSock;
	struct sockaddr_in SAddress;
	socklen_t addr_size; 


	Csock = socket(PF_INET, SOCK_STREAM, 0)

		SAddress
}
learn python fast, or get a tutor.
Topic archived. No new replies allowed.