Tải bản đầy đủ - 0 (trang)
XI.6 Gửi nhận dữ liệu trên mạng Internet

XI.6 Gửi nhận dữ liệu trên mạng Internet

Tải bản đầy đủ - 0trang

sockaddr_in clientService;

clientService.sin_family = AF_INET;

clientService.sin_addr.s_addr = inet_addr( "192.168.1.3" );

clientService.sin_port = htons( 27015 );

if ( connect( m_socket, (SOCKADDR*) &clientService, sizeof(clientService) ) ==

SOCKET_ERROR) {

printf( "Loi ket noi.\n" );

WSACleanup();

return;

}

// Gui va nhan du lieu.

int bytesSent;

int bytesRecv = SOCKET_ERROR;

char sendbuf[32] ="HELLO WORLD";

char recvbuf[32] ="";

printf("\nNhap vao mot chuoi can gui\n");

flushall();

gets(sendbuf);

bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );

printf( "So byte da gui: %ld\n", bytesSent );

bytesRecv = recv( m_socket, recvbuf, 32, 0 );

if ( bytesRecv == 0 ||

(bytesRecv == SOCKET_ERROR &&

WSAGetLastError()== WSAECONNRESET ))

{ if ( bytesRecv == -1 )

{ printf( "Ket noi da dong.\n");

return;

}

if (bytesRecv < 0)

return;

}

printf( "So byte da nhan: %ld\n", bytesRecv );

printf( "Noi dung: %s\n",recvbuf);

return;

}

//server.cpp

#include

#include "winsock2.h"

void main() {

// Khoi tao winsock

WSADATA wsaData;

int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );

if ( iResult != NO_ERROR )

printf("Loi o ham WSAStartup()\n");



411



// Tao mot socket.

SOCKET m_socket;

m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

if ( m_socket == INVALID_SOCKET ) {

printf( "Loi o ham socket(): %ld\n", WSAGetLastError() );

WSACleanup();

return;

}

// Lien ket socket.

sockaddr_in service;

service.sin_family = AF_INET;

service.sin_addr.s_addr = inet_addr( "192.168.1.1" );

service.sin_port = htons( 27015 );

if ( bind( m_socket, (SOCKADDR*) &service, sizeof(service) ) ==

SOCKET_ERROR ) {

printf( "bind() khong duoc.\n" );

closesocket(m_socket);

return;

}

// Lang nghe tren socket.

if ( listen( m_socket, 1 ) == SOCKET_ERROR )

printf( "Error listening on socket.\n");

// Chap nhan ket noi tu client.

SOCKET AcceptSocket;

printf( "Dang cho ket noi tu client ...\n" );

while (1)

{AcceptSocket = SOCKET_ERROR;

while ( AcceptSocket == SOCKET_ERROR ) {

AcceptSocket = accept( m_socket, NULL, NULL );

}

printf( "Client da ket noi.\n");

m_socket = AcceptSocket;

break;

}

// Gui va nhan du lieu

int bytesSent;

int bytesRecv = SOCKET_ERROR;

char sendbuf[32] ="";

char recvbuf[32] ="";

bytesRecv = recv( m_socket, recvbuf, 32, 0 );

printf( "So byte da nhan: %ld\n", bytesRecv );

printf( "Noi dung: %s\n",recvbuf);



412



// Xu ly recvbuf, dao nguoc chuoi nay

for(int i=0;i
sendbuf[i]=recvbuf[strlen(recvbuf)-1-i];

sendbuf[strlen(recvbuf)]='\0';

// Gui tra lai cho client

bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );

printf( "So byte da gui: %ld\n", bytesSent );

Sleep(3000);

return;

}



413



XII. Tài liệu tham khảo

1) S. N. Papakostas, G. Papageorgiou, “A family of fifth-order Runge-Kutta pairs” –

MATHEMATICS OF COMPUTATION Volume 65, Number 215. July 1996, Pages

1165-1181

2) C.W. Gear, “Numerical Initial Value Problems in Ordinary Differential Equations”,

Prentice Hall, 1971.

E. Harier, S.P Norsett, and G. Wanner. “Solving Ordinary Equations” – Springer Series

in Computational Mathematics, 8. Springer, 2. edition, 2000.

3) Gunnar Staff. “Convergence and Stability of the Parareal algorithm: A numerical and

theoretical investigation” – Department of Mathematical Sciences, Norwegian

University of Science and Technology, N-7491 Trondheim, Norway.

4) http://www.math.ntnu.no/preprint/numerics/2003/N2-2003.ps

5) Evan Thomas. “Parallel Algorithms for Biologically Realistic, Large Scale Neural

Modeling” – Department of Computer Science RMIT.

6) Edward A. Billard. “Distributed Computation” – California State University,

Hayward.

7) Peter Pacheco. “Parallel Programming with MPI”.

8) Ian Foster. “Designing and Building Parallel Programs”

9) William Gropp and Ewing Lusk “Tuning MPI Applications for Peak Performance” –

Argonne National Laborary.

10)



IBM Parallel Environment Manuals:



www-1.ibm.com/servers/eserver/pseries/library/sp_books

11)



"Message Passing Interface (MPI)" tutorial from the Cornell Theory Center.



12) "RS/6000 SP Switch Performance" whitepaper. Frank May, IBM Corporation.

June 1998.

13)

“Writing Message-Passing Parallel Programs with MPI.” Course note. Neil

MacDonald, Elspeth Minty, Mario Antonioletti, Joel Malard, Tim Harding, imon Brown

14)

Roger W. Webster, Ph.D. Department of Computer Science “Laboratory

Assignment - Mutual Exclusion”

15)

Edsger W. Dijkstra Technological University, Eindhoven, The Netherlands The

Structure of the "THE"-Multiprogramming System Commun. ACM 11 (1968), 5: 341–

346.

16)



Solution of a Problem in Concurrent Programming Control Communications of

414



the ACM Volume 8 /Number 9 /September, 1965 p:569

17)



“introduction to OpenMP” – subpercomputing Institute of Minnesota University



18)



Srinivasan S. Muthuswamy & Kavitha Varadarajan



415



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

XI.6 Gửi nhận dữ liệu trên mạng Internet

Tải bản đầy đủ ngay(0 tr)

×