Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9123009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:14:13+00:00 2026-06-17T06:14:13+00:00

I have a program that currently works as a chat server. It’s a turn

  • 0

I have a program that currently works as a chat server. It’s a turn based card game with a chat box to communicate with the opponent. The chat stuff all works over the connection, but I’m to the point where I need to start sending certain cards to the opponent, so that when I play a card, my opponent will see it on his screen. I want the client computer to receive the object or collection of objects, figure out what the card type is based on its properties, and then put the card in the correct location. The sending and receiving part is what I don’t understand how to accomplish. From what I’ve read, this requires serialization and I just don’t know where to begin with this. Please assist! I’m using visual studio.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:14:14+00:00Added an answer on June 17, 2026 at 6:14 am

    Answering my own question again… I ended up creating a new class called card container which contains the cardType as a string and the card id as a int. There are also other properties for the card container so I know where the card goes. Then I serialized the card container (which is ‘cc’ in the following code) and sent it as follows:

    Dim cc as new CardContainer
    cc.id = card.id
    cc.cardType = card.GetType.ToString
    cc.discard = true
    
    Dim bf As New BinaryFormatter
    Dim ms As New MemoryStream
    Dim b() As Byte
    
    'serializes to the created memory stream
    bf.Serialize(ms, cc)
    'converts the memory stream to the byte array
    b = ms.ToArray()
    ms.Close()
    
    'sends the byte array to client or host
    SyncLock mobjClient.GetStream
        mobjClient.GetStream.Write(b, 0, b.Length)
    End SyncLock
    

    The client listens on its TCPClient for anything at all and picks up the card with the following code:

        Dim intCount As Integer
    
        Try
            SyncLock mobjClient.GetStream
                'returns the number of bytes to know how many to read
                intCount = mobjClient.GetStream.EndRead(ar)
            End SyncLock
            'if no bytes then we are disconnected
            If intCount < 1 Then
                MarkAsDisconnected()
                Exit Sub
            End If
    
            Dim bf As New BinaryFormatter
            Dim cc As New CardContainer
            'moves the byte array found in arData to the memory stream
            Dim ms As New MemoryStream(arData)
    
            'cuts off the byte array in the memory stream after all the received data
            ms.SetLength(intCount)
            'the new cardContainer will now be just like the sent one
            cc = bf.Deserialize(ms)
            ms.Close()
    
            'starts the listener again
            mobjClient.GetStream.BeginRead(arData, 0, 3145728, AddressOf DoRead, Nothing)
    

    Depending on what data the cardcontainer has determines which method the client now calls. For example, when this is received, the created cc is passed to my CardReceived method which then has a bunch of if, elseif statements. One of those would be

    ElseIf cc.discard = true then
    'makes a new card from the id and cardType properties
    dim temp as new object = MakeCard
    'discard method will find the correct card in the Host's known hand and discard it to the correct pile
    Discard(temp)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a basic chat program in c++ that uses WinSock2.h with UDP.
all. I have built a simple jQuery/PHP chat program that works rather well. However,
I currently have a program that compliments a flash game. One of the features
I have a python program that I am currently working on which is working
We have an app that currently installs itself into 'program files\our app', and it
I have a program that gets a JSON from the server using getJSON and
Hello everyone and thanks for your help! I currently have this program that renames
I currently have a program that basically reads html from a webpage. After sending
I have a piece of C network software that currently works in listen and
I have a Python program that works with dictionaries a lot. I have to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.