1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
// TCPSocket.cpp : implementation file
//
#include "stdafx.h"
#include "server.h"
#include "TCPSocket.h"
#include "Asynlstn.h"
#include "serverDlg.h"
#include "time.h"
#include <sys/time.h>//a pas trouver
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// TCPSocket
TCPSocket::TCPSocket(CDialog* pDlg)
{
m_pDlg = pDlg;
}
TCPSocket::~TCPSocket()
{
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(TCPSocket, CAsyncSocket)
//{{AFX_MSG_MAP(TCPSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// TCPSocket member functions
//Attente ACCEPTATION de connection TCP uniquement
void TCPSocket::OnAccept(int nErrorCode)
{
CAsyncSocket::OnAccept(nErrorCode);
}
//Attente de fermeture de connection
void TCPSocket::OnClose(int nErrorCode)
{
CAsyncSocket::OnClose(nErrorCode);
delete this;
}
//Attente de connection
void TCPSocket::OnConnect(int nErrorCode)
{
CAsyncSocket::OnConnect(nErrorCode);
}
//Signale de l'on peut recevoir des donnees
void TCPSocket::OnReceive(int nErrorCode)
{
TCPSocket* temp;
temp=((CServerDlg*)m_pDlg)->SocketTCP1;
TCHAR buff[127];
unsigned int nRead;
double start,end,dif;
char toto[1];
start=GetClock();
nRead = temp->Receive(buff,sizeof(buff),0);
end=GetClock();
sprintf(toto,"%f",dif);
buff[nRead] = 0; //terminate the string
CString szTemp(buff);
//*************************************************************************************
//Morceau de code rajouter pour enregistrer le dans un fichier
CFile fichier;
fichier.Open("reception.dat",CFile::modeCreate |CFile::modeWrite);
fichier.Write(szTemp,szTemp.GetLength());
fichier.Close();
//*************************************************************************************
//Affiche dans la fenetre principal
//((CServerDlg*)m_pDlg)->m_affiche += "\r\n";
//((CServerDlg*)m_pDlg)->m_affiche += buff;
//((CServerDlg*)m_pDlg)->UpdateData(FALSE);
//Affiche dans les CList
((CServerDlg*)m_pDlg)->m_val1.InsertString(0,toto);
((CServerDlg*)m_pDlg)->m_val2.InsertString(0,&buff[2]);
((CServerDlg*)m_pDlg)->m_val1.DeleteString(20);
((CServerDlg*)m_pDlg)->m_val2.DeleteString(20);
((CServerDlg*)m_pDlg)->m_val1.RedrawWindow();
((CServerDlg*)m_pDlg)->m_val2.RedrawWindow();
CAsyncSocket::OnReceive(nErrorCode);
}
//Signale que l'on peut envoyer
void TCPSocket::OnSend(int nErrorCode)
{
CAsyncSocket::OnSend(nErrorCode);
}
//Reception en TCP
int TCPSocket::Receive(void* lpBuf, int nBufLen, int nFlags)
{
return CAsyncSocket::Receive(lpBuf, nBufLen, nFlags);
}
//Envoie en TCP
int TCPSocket::Send(const void* lpBuf, int nBufLen, int nFlags)
{
return CAsyncSocket::Send(lpBuf, nBufLen, nFlags);
}
//Creation d'un socket TCP
BOOL TCPSocket::Create( UINT nSocketPort , int nSocketType, long lEvent, LPCTSTR lpszSocketAddress )
{
return CAsyncSocket::Create(nSocketPort,nSocketType,lEvent,lpszSocketAddress);
}
//Creation d'un socket TCP
BOOL TCPSocket::Socket( int nSocketType , long lEvent , int nProtocolType , int nAddressFormat )
{
return CAsyncSocket::Socket( nSocketType, lEvent, nProtocolType, nAddressFormat);
}
//Donne un nom au socket
BOOL TCPSocket::Bind( UINT nSocketPort, LPCTSTR lpszSocketAddress)
{
return CAsyncSocket::Bind(nSocketPort,lpszSocketAddress);
}
//Fonction ecoute
BOOL TCPSocket::Listen( int nConnectionBacklog )
{
return CAsyncSocket::Listen( nConnectionBacklog );
}
//Ferme la connection
void TCPSocket::Close()
{
CAsyncSocket::Close();
}
//Derniere erreur
int TCPSocket::GetLastError()
{
return CAsyncSocket::GetLastError();
}
//Obtenir le nom d'un correspondant connecté
BOOL TCPSocket::GetPeerName( SOCKADDR* lpSockAddr, int* lpSockAddrLen )
{
return CAsyncSocket::GetPeerName( lpSockAddr, lpSockAddrLen);
}
//Obtenir le nom de la socket indiquée
BOOL TCPSocket::GetSockName( SOCKADDR* lpSockAddr, int* lpSockAddrLen )
{
return CAsyncSocket::GetSockName( lpSockAddr, lpSockAddrLen );
}
//Indique qu'un message urgent arrive ???
void TCPSocket::OnOutOfBandData(int nErrorCode)
{
CAsyncSocket::OnOutOfBandData(nErrorCode);
} |
Partager