Peer to Peer winsock

Started by
1 comment, last by ziplux 23 years, 4 months ago
Hi again. I've made a program with winsock which listens on a predefined port when it starts. This way, it can either make a conneciton to another computer running this applicaiton or accept a connection from another user. I have two quesitons about this. Is this the only way to save the user from having to choose to become a server or client? I want this process to be transparent, and so I have it automatically listen for connecitons. The other issue I have is that the computer that accepts the connection is unable to send data. I use something like this:
  
// in FD_ACCEPT message of WM_SOCKET

// where client is defined as SOCKET client

// where incoming is the listening socket

int sizeaddr = sizeof (sockaddr);
client = accept (incoming, &client_sock, &sizeaddr); // accept a connection

if (client == INVALID_SOCKET)
	{	// error accepting connection

	WSACleanup ();
	return 0;
	}
else
	{	// client connected successfully

	WSAAsyncSelect(client, g_hwnd, WM_SOCKET, FD_READ | FD_CLOSE);
	return 1;
	}
// then, when I go to send if I'm connecting to another comp and outgoing is the socket to that comp:

send(outgoing, szSendBuff, str.size()+sizeof(dwSize), 0);
// that works fine.  but, if I am the comp being connected to and client is the socket from FD_ACCEPT:

send(client, szSendBuff, str.size()+sizeof(dwSize), 0);
// the other computer never gets the message.

  
Any suggestions? Thanks in advance. My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t X R- tv+ b++ DI+(+++) D- G e* h!" Decode my geekcode! Geekcode.com
Visit our web site: Asylum Entertainment Edited by - ziplux on 12/16/00 2:40:23 PM
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t XR- tv+ b++ DI+(+++) D- G e* h!"Decode my geekcode!Geekcode.com
Visit our web site:Asylum Entertainment
Advertisement
For peer-to-peer networking, I''d strong suggest that you use UDP instead of TCP. With UDP, you only open a single endpoint to communicate with every other host. With TCP, you need to connect() or accept() a connection with each peer.
Matt Slot / Bitwise Operator / Ambrosia Software, Inc.
You either need non-blocking sockets or a thread for the server & a thread for the client.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement