próbuje napisac program majacy pelnic funkcje prostego komunikatora dzialajacego w sieci.
Podpieram sie ksizaka E.Comer Sieci komputerowe i intersieci w ktorej podany jest przyklad, jednak nie udaje mi sie go poprawnie linkowac (kompiluje sie). Oto kod programu serwera:
/* chatserver.c */
#include <stdlib.h>
#include <stdio.h>
#include <cnaiapi.h>
#define BUFFSIZE 256
#define INPUT_PROMPT "Input > "
#define RECEIVED_PROMPT "Received> "
int recvln(connection, char *, int);
int readln(char *, int);
/*-----------------------------------------------------------------------
*
* Program: chatserver
* Purpose: wait for a connection from a chatclient & allow users to chat
* Usage: chatserver <appnum>
*
*-----------------------------------------------------------------------
*/
int
main(int argc, char *argv[])
{
connection conn;
int len;
char buff[BUFFSIZE];
if (argc != 2) {
(void) fprintf(stderr, "usage: %s <appnum>\n", argv[0]);
exit(1);
}
(void) printf("Chat Server Waiting For Connection.\n");
/* wait for a connection from a chatclient */
conn = await_contact((appnum) atoi(argv[1]));
if (conn < 0)
exit(1);
(void) printf("Chat Connection Established.\n");
/* iterate, reading from the client and the local user */
while((len = recvln(conn, buff, BUFFSIZE)) > 0) {
(void) printf(RECEIVED_PROMPT);
(void) fflush(stdout);
(void) write(STDOUT_FILENO, buff, len);
/* send a line to the chatclient */
(void) printf(INPUT_PROMPT);
(void) fflush(stdout);
if ((len = readln(buff, BUFFSIZE)) < 1)
break;
buff[len - 1] = '\n';
(void) send(conn, buff, len, 0);
}
/* iteration ends when EOF found on stdin or chat connection */
(void) send_eof(conn);
(void) printf("\nChat Connection Closed.\n\n");
return 0;
}
a tutaj dostepne sa potrzebne pliki *.h:
http://www.netbook.cs.purdue.edu/cnaiapi/cnaiapi/h/
uzywam borland c++ 5.02, ale w dev-c++ i minGW rowniez nie udalo mi sie utworzyc pliku wykonywalnego.
A blad wyskakuje taki:
Info :Building...
Info :Compiling C:\Documents and Settings\bartek\Pulpit\chat\chatserver.c
Warn : chatserver.c(49,42):'_write' is obsolete
Info :Linking C:\Documents and Settings\bartek\Pulpit\chat\chatserver.exe
Error: Error: Unresolved external 'await_contact(short)' referenced from C:\DOCUMENTS AND SETTINGS\BARTEK\PULPIT\CHAT\CHATSERVER.OBJ
Error: Error: Unresolved external 'readln(char*,int)' referenced from C:\DOCUMENTS AND SETTINGS\BARTEK\PULPIT\CHAT\CHATSERVER.OBJ
Error: Error: Unresolved external 'recvln(int,char*,int)' referenced from C:\DOCUMENTS AND SETTINGS\BARTEK\PULPIT\CHAT\CHATSERVER.OBJ
Error: Error: Unresolved external 'send_eof(int)' referenced from C:\DOCUMENTS AND SETTINGS\BARTEK\PULPIT\CHAT\CHATSERVER.OBJ
Bylbym bardzo wdzieczny za pomoc lub podpowiedz