Προς το περιεχόμενο

Server - Client (VB me VC)


tsipouro

Προτεινόμενες αναρτήσεις

Δημοσ.

Thelw na ftiaksw mia efarmogi server-client (remote control). O Server einai etoimos se Visual Basic kai thelw na ftiaksw ton client se VC. O server tha stelnei (mesw UDP protokolou) lekseis ston client kai analoga me tin leksi, o client tha apantaei pali me antistoixi leksi.

Sti VB xrisimopoiw to WinSock.

Tha mporouse na mou deiksei kapoios pws na ftiaksw ton Client (mono to kommati tis epikoinwnias me ton server diladi) se VC?

 

O logos pou to kanw, einai epeidi i ipoloipi efarmogi tou Client einai se VC.

 

Efxaristw ek twn proterwn...

Δημοσ.

Afou xrisimopoieis winsock ston server, xrisimopoiise winsock kai ston client, me paromoio tropo.

 

ola einai orismena sto "WINSOCK2.H".

 

Paradeigmata exei sto path SAMPLES\WIN32\WSOCK\ tou msdn.

Δημοσ.

kalo to link, alla zalistika.... <img src="http://www.insomnia.gr/ubbthreads/images/graemlins/crazy.gif" alt="" />

 

Se genikes grammes..........

 

' vb sub gia apostoli se UDP

Private Sub Message_Click()

Dim mess As String

MainIP="194.63.247.244"

mess = InputBox(" Doste mou ena mynima na stilo! ", "Message")

mainfrm.Commandsock.RemoteHost = MainIP

mainfrm.Commandsock.RemotePort = 12345

mainfrm.Commandsock.SendData MainIP & "|MESSAGE|" & mess

End Sub

 

afto to programma stelnei....

 

Egw xreiazomai kodika se VC gia na lamvanetai to minima kai na mou apantaei oti to pire!

Mporei na voithisei kaneis?

 

Xilia efxaristw <img src="http://www.insomnia.gr/ubbthreads/images/graemlins/smile.gif" alt="" />

Δημοσ.

Xrisimopoiise tin parakatw uporoutina pou kanei akrivws auto pou thes. Stirixthika ston kwdika apo to link pou sou esteila kai ton diamorfwsa stis anages sou. bebaia, prepei kai esu na ton meletiseis parapera kai na kaneis allages pou xreiazodai. Einai apla mia kali basi gia auto pou thes. Psakse sto MSDN gia tis sunartiseis pou xrisimopoiw.

 

>
#include <stdio.h>
#include <winsock.h>

inline  void PrintError(s)
{
	fprintf(stderr,"\n%: %d\n", s, WSAGetLastError());
}



void StreamClient(char *szServer, short nPort)
{
	WORD wVersionRequested = MAKEWORD(1,1);
	WSADATA wsaData;
	int nRet;

	nRet = WSAStartup(wVersionRequested, &wsaData);
	if (wsaData.wVersion != wVersionRequested)
	{
		fprintf(stderr,"\n Wrong version\n");
		return;
	}

	printf("\nClient connecting to server: %s on port: %d",
				szServer, nPort);

	//
	// Find the server
	//
    LPHOSTENT lpHostEntry;

	lpHostEntry = gethostbyname(szServer);
	if (lpHostEntry == NULL)
	{
		PrintError("gethostbyname()");
		return;
	}

	//
	// Create a UDP stream socket
	//
	SOCKET	theSocket;

	theSocket = socket(AF_INET,				// Address family
					   SOCK_DGRAM,			// Socket type
					   IPPROTO_TCP);		// Protocol
	if (theSocket == INVALID_SOCKET)
	{
		PrintError("socket()");
		return;
	}

	//
	// Fill in the address structure
	//
	SOCKADDR_IN saServer;

	saServer.sin_family = AF_INET;
	saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
										// ^ Server's address
	saServer.sin_port = htons(nPort);	// Port number from command line

	//
	// connect to the server
	//
	int nRet;

	nRet = connect(theSocket,				// Socket
				   (LPSOCKADDR)&saServer,	// Server address
				   sizeof(struct sockaddr));// Length of server address structure
	if (nRet == SOCKET_ERROR)
	{
		PrintError("socket()");
		closesocket(theSocket);
		return;
	}

	char szBuf[256]; //
	//
	// Wait for a reply
	//
	nRet = recv(theSocket,				// Connected socket
				szBuf,					// Receive buffer
				sizeof(szBuf),			// Size of receive buffer
				0);						// Flags
	if (nRet == SOCKET_ERROR)
	{
		PrintError("recv()");
		closesocket(theSocket);
		return;
	}


	//
	// Display the received data
	//
	printf("\nData received: %s", szBuf);

	//
	// Send data to the server
	//

	strcpy(szBuf, "From the Client");
	nRet = send(theSocket,				// Connected socket
				szBuf,					// Data buffer
				strlen(szBuf),			// Length of data
				0);						// Flags
	if (nRet == SOCKET_ERROR)
	{
		PrintError("send()");
		closesocket(theSocket);
		return;
	}


	WSACleanup();

	closesocket(theSocket);
	return;

}

Δημοσ.

Danke Danke Danke Danke Danke Danke <img src="http://www.insomnia.gr/ubbthreads/images/graemlins/blush.gif" alt="" /> <img src="http://www.insomnia.gr/ubbthreads/images/graemlins/ooo.gif" alt="" /> <img src="http://www.insomnia.gr/ubbthreads/images/graemlins/shocked.gif" alt="" /> <img src="http://www.insomnia.gr/ubbthreads/images/graemlins/smile.gif" alt="" />

Δημοσ.

epeidi thelw gia UDP protokolo, mou grafeis:

 

SOCKET theSocket;

 

theSocket = socket(AF_INET, // Address family

SOCK_DGRAM, // Socket type

IPPROTO_TCP); // Protocol

if (theSocket == INVALID_SOCKET)

{

PrintError("socket()");

return;

}

 

an allaksw to TCP se UDP, tha doulepsei??

thnx

Δημοσ.

nai, kane to IPPROTO_UDP. Alla den katalabainw giati thes na xrisimopoiiseis UDP prwtokolo. Einai anaksiopisto. Ektos bebaia kai an einai meros kapoias askisis me sugekrimeni ekfwnisi pou prepei na kaneis.

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...