I have an unusual question that I hope to get input on. I'm new to network programming and am learning socket programming via the .NET "TcpListener" and "TcpClient" classes in the System.Net.Sockets namespace. I need to use them in an unusual manner though: I need to be able to establish a connection between computer A and computer B. Computer A will be running an instance of the "TcpClient" class and will attempt to open a connection to computer B which is running an instance of "TcpListener". This part seems straight forward. However, once the connection has been established I need to reverse the roles so that computer A becomes the machine that waits for and responds to messages sent from computer B. In other words computer A then becomes the server and computer B becomes the client. This role reversal must use the same connection that was opened by computer A when it was initially acting as a client. It's not clear to me how to do this as all the examples and the (excellent) book "TCP/IP Sockets in C#" I'm reading always use these classes in their predefined roles. Is there actually a way to do this? Do I have to drop down to the "Socket" class rather than use the more abstracted "TcpListener/TcpClient" classes?
How to reverse roles of TcpListener/TcpClient?
266 Views Asked by LKeene At
0
There are 0 best solutions below
Related Questions in C#
- Passing arguments to main in C using Eclipse
- kernel module does not print packet info
- error C2016 (C requires that a struct or union has at least one member) and structs typedefs
- Drawing with ncurses, sockets and fork
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- Configured TTL for A record(s) backing CNAME records
- Allocating memory for pointers inside structures in functions
- Finding articulation point of undirected graph by DFS
- C first fgets() is being skipped while the second runs
- C std library don't appear to be linked in object file
- gcc static library compilation
- How to do a case-insensitive string comparison?
- C programming: Create and write 2D array of files as function
- How to read a file then store to array and then print?
- Function timeouts in C and thread
Related Questions in SOCKETS
- Drawing with ncurses, sockets and fork
- UDP sockets in C not working
- How can I send multiple objects over one socket in java?
- psuedo TCP multicast with os.dup2() in python?
- My get request for http is very slow
- Nodejs connect mysql socket to another host?
- HttpRequestContext vs HttpContext
- Spring based client server communication without network
- Java does not accept 2 methods with same name
- Retrieve Data From EOC(Eithernet Over coxial) device
- Ping a server without freezing the Thread
- C sockets: Exit client after all data is received
- What is the best way to send XML converted to a byte array over TCP, then translate the response back to readable XML?
- C# Winform to Connect to Device Using IP
- Java Restart a Socket
Related Questions in TCPCLIENT
- Connecting a web client to a c++ server with TCP
- Is TcpClient a single connection use? How do I send a second message?
- New Instance of TCPClient Exception
- Tcp Port connection shows incompatible value
- Configuring client throughput in simple TCP server
- c# TCP Server Client Threading Issies
- Knowning when a NetworkStream is closed
- Only one usage of each socket address (protocol/network address/port) is normally permitted in c#
- Connect to pressure sensor using c# to get the value ,doesn't work in c#
- NetworkStream callback called multiple times on server when client closes connection
- Why is socket slowing down after a number of reads?
- Matlab tcpip server receiving data from c program
- Async TcpClient events on data available c#
- Array of Background Worker to Read Tcpclient continuously
- how to receive data from a Socket in .NET Core?
Related Questions in TCPLISTENER
- Tcp Port connection shows incompatible value
- c# TCP Server Client Threading Issies
- Knowning when a NetworkStream is closed
- XmlDocument.Load() is freezing, but not receiving any error
- ASP.NET/IIS: How can I serve TCP connections using a custom protocol (i.e. without WCF)?
- Remove any pending data to read after socket timeout
- How to handle multiple TcpClient clients simultaneously
- Listening packets on specific IP and port
- Extended class of TcpClient doesn't accept with EndAcceptTcpClient(ar) function
- Why TCP communication between ports on local machine is not working on different Windows OS's?
- Can .NET TcpListener class receive data sent via SSH (SFTP)
- async tcp connection C#
- Socket is not receiving data from localhost
- Server Program won't read from Stream
- C# TCP Client having trouble listening to Server and updating GUI
Related Questions in SYSTEM.NET.SOCKETS
- C# Exception in receiving message with UDP
- ExtendedSocketException encountered when calling TcpClient.ConnectAsync() from a UWP app
- Would Asyncronous TCP networking be a better option for a dedicated server with up to 32 players playing at the same time in C#?
- How to Create a TCP Client connection with a Client Certificate in Powershell
- How to receive all data properly via TCP/IP C#
- Getting the same data into a buffer from TCP/IP server
- How to get length of data received in socket?
- Problem with sending file via socket in Base64
- Why does Visual Studio break System.Net.Socket with each different user session?
- nullreference of system.net.sockets on monotouch
- Receiving None Standard Layer 2 Packets in .NET
- How to achieve a "peer-to-peer" connection with TCPClient/TCPListener in System.Net.Sockets C# (NAT Traversal, no portforward, hole punching)
- Partial Send in Socket.BeginSend( List<ArraySegment> )?
- How to create new ServerSocket C#
- How to be able keep on sending from client to server without follow the sequence and freeze?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?