TCP Port |
Purpose |
Problem |
Server protocol |
6661 |
Basic test |
None |
Connect, and receive a "Hello!" string. Terminated by exclamation point (or EOF). |
6662 |
Newline string echo |
441hw3.1 |
Send one newline-terminated string. Receive the same string back again. |
6663 |
Addition | 441hw3.2 | Send two int32 numbers, get back one int32 number, the sum. |
6664 |
Counted string |
441hw3.3 |
Send one int32 string length, then a string of that length. Get back the string length (only, no data). |
6665 |
Simple callback |
441hw3.4 |
Create your own listening TCP port. Send the server an int32 with your port number. The server will connect on this port. On this new connection, you then send the server a newline-terminated string, and the server will respond with the int32 length of the string you sent. |
6666 |
Authenticated callback |
441hw3.5 |
Create your own listening TCP port. Send the server an int32 with your port number. The server will connect on this port, and perform these steps: Authenticate: Server sends 0xBEEF as an int32. You send back 0xF00D as an int32. Server sends a challenge int32. You add 0xF00D to the challenge and send that int32 back. Communicate: You send a newline-terminated string. We store this string. Server sends back client's string, or an error message. Close connection |
6669 |
Log reader (debugging) |
None |
Send two int32's: your student ID, and the server port you want the logs for. Returns an int32 log length, and the logs from that server matching your ID. |
#include "osl/socket.h"Of course, you need to use your own student ID and server number. The 6669 server itself logs your request, so every time you run the above, you should see another entry with your ID and the date.
#include "osl/socket.cpp"
int foo(void) {
skt_ip_t ip=skt_lookup_ip("137.229.25.20"); // powerwall0
int port=6669; // one demo server
int timeout=1; // seconds until timeout (usually 60)
SOCKET s=skt_connect(ip,port,timeout);
std::cout<<"Connected.\n";
// Send off my ID
Big32 id=36661313;
skt_sendN(s,&id,sizeof(id));
// Send off the requested server number
Big32 server=6669;
skt_sendN(s,&server,sizeof(server));
// Receive a string with all occurrences in the logfiles.
Big32 len=0;
skt_recvN(s,&len,sizeof(len));
unsigned int slen=len;
std::cout<<"Server is sending back "<<slen<<" bytes.\n";
if (slen>0 && slen<100000) {
std::string str(slen,'x');
skt_recvN(s,&str[0],slen);
std::cout<<"Back from server: \n"<<str<<"\n";
}
skt_close(s);
return 0;
}