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 1928342
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:57:59+00:00 2026-05-17T06:57:59+00:00

I created a basic tcp client and server in groovy and I’m wanting to

  • 0

I created a basic tcp client and server in groovy and I’m wanting to send maps from the server to the client, I’m wondering if I’m able send maps across and still being able to access the values.

//TCP Server
def book1 = [Title of Book: "Groovy Recipes", Author: "Scott Davis", Number of Pages: "241"]

server = new ServerSocket(2000)

println("Waiting for connection")

while(true) {
    server.accept() { socket ->
        socket.withStreams { input, output ->   

            w = new BufferedWriter(new OutputStreamWriter(output))
            String message = "Connection was successful"

            r = new BufferedReader(new InputStreamReader(input))

            while(true) {

                if(message != null) {
                    w.writeLine(message)
                    w.flush()
                    message = null
                }

                String a = r.readLine()

                if(a=="book1") {
                    message = book1
                } else {
                    message = "$a command unknown."
                    sendMessage(message)
                    println message
                    message = null
                }
            }
        }
    }
}

def sendMessage(String msg) {
    try {
        w.writeLine(msg)
        w.flush();
    } catch(IOException ioException) {
        ioException.printStackTrace();
    }
}

Here is my Client (where I’m wanting to receive the map and get the values)

//TCP Client

def grabBookInfo {
    queryData()  
}

public void queryData() {
    def hosts = ["localhost"]

    for(int aHost = 0; aHost < hosts.size; aHost++) {
        bookClient(hosts[aHost]);
    }
}

public void bookClient() {
    def commands = ["book1"]
    def answers = [commands.size]

    def requestSocket = new Socket(host, 2000)

    r = new BufferedReader(new InputStreamReader(requestSocket.getInputStream()));
    w = new BufferedWriter(new OutputStreamWriter(requestSocket.getOutputStream()));

    String message = "Connection was successful"

    message = r.readLine()
    println("Server>" + message)

    for(int n = 0; n < commands.size; n++) {
        sendMessage(commands[n]);
        answers[n] = r.readLine()
    }

    //get map values here
    //answers[0] = Book
    //println Book.['Title of Book']
    //println Book.['Author']
    //println Book.['Number of Pages']

    w.flush()
    w.close()
}

public void sendMessage(msg) {
    w.write(msg+"\r\n");
    w.flush();
    System.out.println("client>" + msg);
    }   
}

Am I on the right track?

  • 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-05-17T06:58:00+00:00Added an answer on May 17, 2026 at 6:58 am

    Serialize the maps, example

    http://www.java2s.com/Tutorial/Java/0140__Collections/SerializingHashMaps.htm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a basic Client Server that will send image files in a
I have created a simple Twisted based TCP server and Android client. I have
I created a basic TCP server that reads incoming binary data in protocol buffer
I've created a basic orthographic shader that displays sprites from textures. It works great.
I've created a basic MVC REST API to just get single Person from the
Currently I created the chating application which is windows application(c#). I created basic Client
I'm currently programming a Basic Client Server messaging program in C. The problem I
I have a Rails 3.2.2 application using Ruby version 1.9.2. I have created basic
I created a basic calculator service called MiniCalc that only has two operations. Add
I have created a basic shape in HTML canvas element which works fine. The

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.