COMP445 Fall 2006: Lab Assignment 1
COMP445 Fall 2006: Lab Assignment 1
Fall 2006
Lab assignment 1
CALLER
RECEIVER
STEP1: Get the name of the second party
STEP1: Plug the
phone, and listen
for incoming calls
on a certain line
Program architecture
Client
Server
port 7070
Socket Programming
Berkeley added a new interface to the operating system
to support network communication. This interface is
generally known as the Berkeley Sockets Interface and
is the basis for almost all existing TCP/IP network
protocol interfaces, including Windows Sockets
Socket Functions
CLIENT
SERVER
PURPOSE: File Transfer
-Get a file
-Send a file
10
//GET or PUT
//filename
struct MESSAGE_FRAME {
unsigned char header; //ERROR,DATA,LASTPACKET, etc.
char data[MAX_SIZE]; //data or error message
} message_frame;
YOU ARE FREE TO DESIGN YOUR OWN STRUCTURES
11
}
else
printf( "File could not be opened\n" );
}
fclose( stream );
}
Be careful if you use strcpy when reading from a binary file use memcpy.
12
Writing in a file
void main( void ) {
FILE *stream;
int numread, numwritten;
if( (stream = fopen( "fread.out", "w" )) != NULL ) {
}
else{
printf( "Problem opening the file\n" );
}
fclose( stream );
}
13
switch (message_frame.header){
case 1
:
;
break;
case 2
:
;
break;
case 3
:
;
break;
default:
}
14
Hints
Use a log file in each side in order to
monitor all the actions:
receiving a packet
sending a packet, etc.
Open and close the log file after each
read/write operation if your program freezes
and you cannot read the log file.
Do not use any string library function! You
will be able to send only text files but not
binary ones (jpeg or exe for example).
Instead use memcpy for transferring data.
Do not care about the order of the receiving
packets in this assignment (TCP will do it for
you).
15
Assignment 1
No GUI
Use Visual C++ 6
Groups of NOT more than 2
wsock32.lib or you add the following
command to your code:
#pragma comment(lib,"wsock32.lib")
Multi-thread in Windows
uintptr_t _beginthread( void( __cdecl *start_address )( void * ), unsigned stack_size, void
*arglist );
Parameters:
start_address
Start address of routine that begins execution of new thread.
stack_size
Stack size for new thread or 0.
arglist
Argument list to be passed to new thread or NULL.
17
19