00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "Sender.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024 Sender::Sender( int iPort)
00025 {
00026 m_iPort=iPort;
00027 }
00028
00029
00030
00031
00032
00033
00034
00035 void Sender::run(void)
00036 {
00037 RNPRESULT rnprTmp;
00038 char pcEingabe[1024];
00039
00040
00041 printf("IP >");
00042 gets(pcEingabe);
00043
00044
00045 RNPacket rnpSend;
00046
00047 if(rnpSend.initMessageCallBack(this,StaticMessageHandler) == RNP_OK)
00048 {
00049 printf("MessageHandler inited.\n");
00050 }
00051 else
00052 {
00053 return;
00054 }
00055
00056
00057 printf("Trying to connect...");
00058
00059 do
00060 {
00061 rnprTmp=rnpSend.socketConnect(pcEingabe,m_iPort);
00062
00063 if (kbhit())
00064 {
00065 printf("\nUser aborted.\n");
00066 getch();
00067 return;
00068 }
00069
00070 Sleep(100);
00071 printf(".");
00072 } while (rnprTmp == RNP_SOCKET_NOT_CONNECTED);
00073
00074 printf("\n");
00075
00076
00077 if (rnprTmp != RNP_OK)
00078 {
00079 printf("Error occured.\n");
00080 return;
00081 }
00082
00083 printf("Connected to %s.\n",pcEingabe);
00084
00085 DWORD dwPacketNr=0;
00086 int iCharCount;
00087
00088
00089 while(true)
00090 {
00091 printf("File >");
00092
00093 gets(pcEingabe);
00094
00095
00096 if (pcEingabe[0]==0)
00097 {
00098 break;
00099 }
00100
00101
00102 FILE* pfileIn=fopen(pcEingabe,"r");
00103 iCharCount=0;
00104
00105
00106 if (pfileIn==NULL)
00107 {
00108 printf("File does not exist! Sending input itself.\n");
00109 }
00110 else
00111 {
00112 printf("Sending file...\n");
00113 }
00114
00115
00116 MessageCharFragment msgcfTmp;
00117 msgcfTmp.m_Type=MSGID_CHARFRAGMENT;
00118 msgcfTmp.m_dwNextPacketNr=c_dwFirstCharFragment;
00119
00120 int iBuf;
00121
00122
00123 do
00124 {
00125
00126 msgcfTmp.m_dwPacketNr=msgcfTmp.m_dwNextPacketNr;
00127
00128 int iCount;
00129
00130
00131 for (iCount=0; iCount<c_dwSizeCharFragment; iCount++)
00132 {
00133 if (pfileIn!=NULL)
00134 {
00135 iBuf=fgetc(pfileIn);
00136 }
00137 else
00138 {
00139 iBuf=pcEingabe[iCharCount];
00140
00141 if (iBuf==0)
00142 {
00143 iBuf=EOF;
00144 }
00145 else
00146 {
00147 iCharCount++;
00148 }
00149 }
00150
00151 msgcfTmp.m_cBuffer[iCount]=(char)iBuf;
00152
00153
00154 if (iBuf==EOF)
00155 {
00156 msgcfTmp.m_cBuffer[iCount]=0;
00157 }
00158 }
00159
00160
00161 if (iBuf==EOF)
00162 {
00163 msgcfTmp.m_dwNextPacketNr=c_dwLastCharFragment;
00164 }
00165 else
00166 {
00167 msgcfTmp.m_dwNextPacketNr=dwPacketNr;
00168 dwPacketNr++;
00169 }
00170
00171
00172 do
00173 {
00174 rnprTmp=rnpSend.sendMessage((void*)&msgcfTmp,sizeof(msgcfTmp));
00175
00176
00177 if (kbhit())
00178 {
00179 break;
00180 }
00181
00182 } while (rnprTmp==RNP_SOCKET_NOT_WRITEABLE);
00183
00184
00185 if (rnprTmp != RNP_OK)
00186 {
00187 printf("Connection closed...\n");
00188 return;
00189 }
00190
00191
00192 if (kbhit())
00193 {
00194 printf("\nUser aborted.\n");
00195 getch();
00196 return;
00197 }
00198
00199 } while (iBuf!=EOF);
00200
00201
00202 printf("All Packets send.\n");
00203 if (pfileIn != NULL)
00204 fclose(pfileIn);
00205 }
00206
00207
00208 if(rnpSend.socketClose() == RNP_OK)
00209 {
00210 printf("Socket closed.\n");
00211 }
00212 else
00213 {
00214 printf("Error occured while closing Socket.\n");
00215 }
00216
00217 }
00218
00219
00220
00221
00222
00223
00224
00225 RNPRESULT Sender::StaticMessageHandler( void* pvoidUserContext,
00226 void* pvoidPacket,
00227 WORD wSize)
00228 {
00229 Sender* pThisObject = (Sender*) pvoidUserContext;
00230
00231 return pThisObject->MessageHandler(pvoidPacket,wSize);
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241 RNPRESULT Sender::MessageHandler(void* pvoidPacket, WORD wSize)
00242 {
00243 MessageGeneric* pmsgTmp= (MessageGeneric*)pvoidPacket;
00244
00245
00246
00247
00248
00249
00250
00251 return RNP_BUFFER_RETURNED;
00252 }
00253
00254
00255
00256