-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'hayguen/master'
- Loading branch information
Showing
12 changed files
with
192 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
#include "PassiveSocket.h" // Include header for active socket object definition | ||
|
||
#define MAX_PACKET 4096 | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
CPassiveSocket socket; | ||
CActiveSocket *pClient = NULL; | ||
|
||
//-------------------------------------------------------------------------- | ||
// Initialize our socket object | ||
//-------------------------------------------------------------------------- | ||
socket.Initialize(); | ||
|
||
socket.Listen("127.0.0.1", 6789); | ||
|
||
while (true) | ||
{ | ||
if ((pClient = socket.Accept()) != NULL) | ||
{ | ||
//---------------------------------------------------------------------- | ||
// Receive request from the client. | ||
//---------------------------------------------------------------------- | ||
if (pClient->Receive(MAX_PACKET)) | ||
{ | ||
//------------------------------------------------------------------ | ||
// Send response to client and close connection to the client. | ||
//------------------------------------------------------------------ | ||
pClient->Send( pClient->GetData(), pClient->GetBytesReceived() ); | ||
pClient->Close(); | ||
} | ||
|
||
delete pClient; | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Receive request from the client. | ||
//----------------------------------------------------------------------------- | ||
socket.Close(); | ||
|
||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
#include <string.h> | ||
#include "ActiveSocket.h" // Include header for active socket object definition | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
CActiveSocket socket; // Instantiate active socket object (defaults to TCP). | ||
char time[50]; | ||
|
||
memset(&time, 0, 50); | ||
|
||
//-------------------------------------------------------------------------- | ||
// Initialize our socket object | ||
//-------------------------------------------------------------------------- | ||
socket.Initialize(); | ||
|
||
//-------------------------------------------------------------------------- | ||
// Create a connection to the time server so that data can be sent | ||
// and received. | ||
//-------------------------------------------------------------------------- | ||
if (socket.Open("time-C.timefreq.bldrdoc.gov", 13)) | ||
{ | ||
//---------------------------------------------------------------------- | ||
// Send a requtest the server requesting the current time. | ||
//---------------------------------------------------------------------- | ||
if (socket.Send((const uint8 *)"\n", 1)) | ||
{ | ||
//---------------------------------------------------------------------- | ||
// Receive response from the server. | ||
//---------------------------------------------------------------------- | ||
socket.Receive(49); | ||
memcpy(&time, socket.GetData(), 49); | ||
printf("%s\n", time); | ||
|
||
//---------------------------------------------------------------------- | ||
// Close the connection. | ||
//---------------------------------------------------------------------- | ||
socket.Close(); | ||
} | ||
} | ||
|
||
|
||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.